[systemd-devel] [PATCH] Return error code 3 with systemctl status after killall LSB server

Lennart Poettering lennart at poettering.net
Fri Jul 1 14:17:57 PDT 2011


On Fri, 01.07.11 00:00, Steven Dake (sdake at redhat.com) wrote:

> This patch is probably not correct, but not having a clear
> understanding of the systemd states, I'm not sure how to properly
> fix the problem.
> 
> The test case is as follows:
> service httpd start
> killall httpd
> service httpd status
> echo $?
> (0 printed, 3 should be printed according to LSB)
> 
> Then attempting to start the service again does not allow it to be
> started, likely because its in the "active" state.  I would expect
> it would be in some other state besides active, such as failed,
> atleast for LSB scripts.

The problem here is that apache is a SysV init script, and for those it
is not really clear whether it is a problem that no process is running
anymore or if that's just the normal case. I.e. consider scripts like
the NFS or ALSA scripts which just set something up and exit. OTOH there
are daemons like apache where it is clearly a problem if nothing is
running anymore. But from systemd's perspective we don't really have a
chance figuring out which kind of service a particular init script is,
and hence we must assume that even though no process is running anymore
for the service it still is "active", which "systemctl status
httpd.service" will show you. However we will show "(exited)" next to
it, to make clear that while we still consider the service active, it
doesn't have any running processes anymore.

Furthermore when you send SIGTERM to apache, it exits with exit code 0,
which is a clean error code. That means that systemd will not put the
service in "failed" state.

The right fix is probably to write a native systemd file for Apache,
where these problems don't really exist. Looking at the F15 version of
the Apache init script this should actually be very simple to
do. Something like this would probably already suffice:

<snip>
[Unit]
Description=Apache Web Server

[Service]
Type=forking
PIDFile=/var/run/httpd/httpd.pid
ExecStart=/usr/sbin/httpd
ExecReload=/usr/sbin/apachectl reload

[Install]
WantedBy=multi-user.target
<snip>

With a unit file like this in place systemd will properly detect whether
Apache is running or not, and show that in "systemctl status" and its
exit code.

(Note that in an ideal world we'd use Type=notify here instead of having
apache fork, but that requires minimal patching of Apache.)

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list