[systemd-devel] Q: Reducing the output of systemctl status
Lennart Poettering
lennart at poettering.net
Wed May 15 09:04:47 UTC 2019
On Mi, 15.05.19 08:49, Ulrich Windl (Ulrich.Windl at rz.uni-regensburg.de) wrote:
> Hi!
>
> First, is it a well-known bug that "--quitet" seems to be ignored for
> "systemctl status"? It's the only command where --quiet makes sense IMHO, but
> it seems to have no effect in v228.
"systemctl status" is the human-friendly operation, i.e. when you want
to know everything about a service.
If you want the short, parsable version use "systemctl is-active", and
possibly add "-q".
> Also, considering this example output:
> ---
> ● iotwatch at LOC1.service - iotwatch I/O performance monitor instance "LOC1"
> Loaded: loaded (/run/systemd/generator.late/iotwatch at LOC1.service; bad;
> vendor preset: disabled)
> Active: active (running) since Wed 2019-05-15 08:33:14 CEST; 2min 17s ago
> Docs: man:iotwatch(1)
> man:iotwatch at .service(8)
> Process: 13962 ExecStartPost=/usr/bin/sleep 0.2 (code=exited,
> status=0/SUCCESS)
> Process: 13950 ExecStart=iotwatch-LOC1 -l
> /var/log/iotwatch/LOC1/iotwatch-LOC1.log -m N
> -p/var/run/iotwatch-LOC1/iotwatch-LOC1.pid -d1 -a0.02 -b512 -i4 -sE -t2.0
> -TA=0.025:0.035,X=0.25:0.75 -OR
> -OS:T=F75,S:M=O52,N:3.29/40,Q:C=100,P:nagios.nagios=0664 /etc/passwd
> (code=exited, status=0/SUCCESS)
> Process: 13929 ExecStartPre=/bin/sh -c [ -d "/var/log/iotwatch/LOC1" -o 1
> -eq 0 ] || mkdir "/var/log/iotwatch/LOC1" || exit 3 (code=exited,
> status=0/SUCCESS)
> Process: 13913 ExecStartPre=/bin/sh -c [ -h
> "/var/run/iotwatch-LOC1/iotwatch-LOC1" ] || ln -s "/usr/bin/iotwatch"
> "/var/run/iotwatch-LOC1/iotwatch-LOC1" || exit 3 (code=exited,
> status=0/SUCCESS)
> Process: 13903 ExecStartPre=/bin/sh -c [ -d "/var/run/iotwatch-LOC1" ] ||
> mkdir "/var/run/iotwatch-LOC1" || exit 3 (code=exited, status=0/SUCCESS)
> Main PID: 13960 (iotwatch-LOC1)
> Tasks: 4 (limit: 512)
> CGroup: /system.slice/system-iotwatch.slice/iotwatch at LOC1.service
> └─13960 iotwatch-LOC1 -l /var/log/iotwatch/LOC1/iotwatch-LOC1.log
> ...
>
> May 15 08:33:14 rksapv04 systemd[1]: Starting iotwatch I/O performance
> moni.....
> May 15 08:33:14 rksapv04 systemd[1]: Started iotwatch I/O performance
> monit...".
> ---
> I wonder if I could suppress the "lesser-important" output, like pre- and post
> start commands.
Quite frankly: this service should probably not embedd so much shell
in the ExecXYZ= command lines in the first place, that'd make
everything a lot more readable...
I mean, it's the price you pay: if your service doesn't do all
necessary checks and preparations on its own, and you push all that
into the service file, then yes, the output will look awful. But the
answer is: don't do that: either fix your daemon to not require
anything like that, or maybe add a wrapper script that does what you
are doing here and then ultimately does an "exec" on the actual
service binary.
Or to say this differently: ExecStartPre= and the other command lines
are supposed to be readable, and in most cases contain something brief
and readable and for those we include in the output and it's a good
thing. But in your case the service file is misused as a shell
replacement, and that's why it looks ugly, but the fix is not use a
shell where a shell is great for and not to break the status output
for everybody else, too.
> (Actually I had to add a manual sleep as the PID file is created by the child
> process after the parent exited, and systemd complained the PIDFile is not
> present yet.)
That looks like a bug in the service. PID files need to be written out
by the time the parent process of a forking daemon exits. That's not
just systemd that needs that, it's exactly the same on sysv too
because otherwise "/etc/init.d/foo start && /etc/init.rd/foo stop"
will always be racy.
> I just noticed: If you use a "argv[0] override" for your command, it's not
> just that the command is started with that name, it's also displayed as
> ExecStart here (not path shown). I used it to shorten error messages using
> argv[0].
I cannot parse this?
> So I'd like a status output that simply displays:
> Active: active (running) since Wed 2019-05-15 08:33:14 CEST; 2min 17s ago
I mean, I'd like a pony, too.
It appears you want to use "systemctl is-active", not "systemctl status".
Lennart
--
Lennart Poettering, Berlin
More information about the systemd-devel
mailing list