Output from systemctl start/restart/stop
Asked Answered
M

3

32

I want to see output from my systemctl commands. For example:

systemctl restart systemd-networkd  

would display the output of

systemctl status systemd-networkd. 

I know that I could write a script that always puts the commands sequentially but I am hoping there is something like

systemctl --verbose restart ....

that didn't make it into the man page.

Monoicous answered 21/3, 2018 at 0:6 Comment(6)
systemctl usually carries stdout output to a log file, for most systems this file is /var/log/syslog . Is that what you mean?Acidulent
@Acidulent I'm looking for an immediate display of status after issuing the systemctl command. To view the log output I will have to issue another command. I am looking for a switch that will have the effect of #systemctl restart <servicename>; systemctl status <servicename>Monoicous
May I refer you to Lennarts response: bug reportHintz
@RichardCross Thank you. What am I to take of it. This report is older than my original post. systemctl does not offer a verbose switch -- or something like it-- which is what I'm looking for.Monoicous
@StephenBoston I too was looking for a verbose option on systemctl, and was disappointed to find there isnt one. As you originally suggested it would make perfect sense to have a --verbose or -v option. Without going into the politics, Lennart has a controlling interest in systemd, and given his response in the bug report I linked to; I would suggest there there unfortunately wont ever be a verbose option.Hintz
@RichardCross Ah commiseration, yes. Oh well. I suppose he wants to keep the code as simple as he can. Okay. Thanks for the link.Monoicous
A
5

To my knowledge, there is no such thing. That being said, you can go ahead and "make you own":

We're going to edit out bashrc file to add this as a an alias command

echo "startstat(){ systemctl start \$*; systemctl status \$* }" >> ~/.bashrc

Note that this will only work for bash sessions and for the user you're running it for, so don't run this inside stuff that doesn't run bashrc before starting.

You can then start services and immediately get the status by running

startstat [arguments to pass to BOTH systemctl start AND systemctl status]

Sample usage:

startstat systemd-networkd 

If you want to wait a little bit before checking the status, you can always add a sleep between:

Just nano ~/.bashrc, scroll to the bottom (or if you added things, whichever line it's at), and just add sleep [seconds]; between systemctl start \$*; and systemctl status \$*;

If you want the status to be run after the start is finished, you can put a singular & sign with a space in front of it between the \$* and the ; to fork it off into background.

Acidulent answered 17/5, 2018 at 17:9 Comment(1)
Thank you very much for this @dGramop . I do have a simple script, but I was wondering if there was a switch. It seems like a natural.Monoicous
S
5

Unfortunately systemctl does not provide a "verbose" option like most Unix commands do.

One solution is to increase SYSTEMD_LOG_LEVEL to debug (info is useless here) and then filter the output like e.g.:

$ SERVICES="smartmontools cron xxxxx"
$ SYSTEMD_LOG_LEVEL=debug systemctl restart $SERVICES 2>&1|egrep "Got result|Failed"
Failed to restart xxxxx.service: Unit xxxxx.service not found.
Got result done/Success for job cron.service
Got result done/Success for job smartmontools.service

You can also add a prefix like e.g.

$ SYSTEMD_LOG_LEVEL=debug systemctl restart $SERVICES 2>&1|egrep -i "Got result|Failed"|sed 's,^,restart: ,'
restart: Failed to restart xxxxx.service: Unit xxxxx.service not found.
restart: Got result done/Success for job cron.service
restart: Got result done/Success for job smartmontools.service

SYSTEMD_LOG_LEVEL might not be available on all systems.

Segal answered 2/8, 2022 at 11:50 Comment(0)
P
4

systemctl does not have a verbose option. If you want to see the output of the service you are running in real time, what you can do is to open another terminal and run:

sudo journalctl --unit=systemd-networkd.service -f

Journalctl documentation: https://www.freedesktop.org/software/systemd/man/journalctl.html

Plutocracy answered 29/6, 2023 at 23:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.