0

I want to know if there is a brief way to check the last 50 lines about a service that threw an error on restart.

$ sudo service nginx restart
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

I use an alias for checking that, tho I forget what the flags do.

alias jrn='sudo journalctl -eu'
$ jrn nginx

-- Reboot -- Jun 26 02:52:42 xi systemd[1]: Starting NGINX Plus - high performance web server... Jun 26 02:52:42 xi systemd[1]: Started NGINX Plus - high performance web server. Jun 26 04:03:16 xi systemd[1]: Stopping NGINX Plus - high performance web server... Jun 26 04:03:16 xi systemd[1]: nginx.service: Succeeded. Jun 26 04:03:16 xi systemd[1]: Stopped NGINX Plus - high performance web server. Jun 26 04:03:16 xi systemd[1]: Starting NGINX Plus - high performance web server... Jun 26 04:03:16 xi nginx[41832]: nginx: [emerg] bind() to 0.0.0.0:3000 failed (98: Address already in use) Jun 26 04:03:17 xi nginx[41832]: nginx: [emerg] bind() to 0.0.0.0:3000 failed (98: Address already in use) Jun 26 04:03:17 xi nginx[41832]: nginx: [emerg] bind() to 0.0.0.0:3000 failed (98: Address already in use) Jun 26 04:03:18 xi nginx[41832]: nginx: [emerg] bind() to 0.0.0.0:3000 failed (98: Address already in use) Jun 26 04:03:18 xi nginx[41832]: nginx: [emerg] bind() to 0.0.0.0:3000 failed (98: Address already in use) Jun 26 04:03:19 xi nginx[41832]: nginx: [emerg] still could not bind() Jun 26 04:03:19 xi systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE Jun 26 04:03:19 xi systemd[1]: nginx.service: Failed with result 'exit-code'. Jun 26 04:03:19 xi systemd[1]: Failed to start NGINX Plus - high performance web server.
listenlight
  • 103
  • 2
  • 4

1 Answers1

2

-u stands for unit.
-e stands for pager end

From the documentation:

This implies -n1000 to guarantee that the pager will not >buffer logs of unbounded size.

For example to get the last 50 lines for nginx you would execute:

journalctl -n 50 -u nginx
Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
Lorem ipsum
  • 892
  • 5
  • 15