Score:0

Tail the journalctl log on failure to restart systemd service?

lb flag

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.
Score:1
us flag

-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
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.