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

2011-07-04 Thread Michal Schmidt
On Fri, 1 Jul 2011 23:17:57 +0200 Lennart Poettering wrote:
 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.

This is true in general, but sometimes we do have enough information
to distinguish the two cases.

For instance, the presence of the chkconfig pidfile: header in the
initscript is an excellent indication that it's not a oneshot script
(like iptables), but a real daemon (like httpd).

This patch works for me.
Comments?

Michal

diff --git a/src/service.c b/src/service.c
index 165655e..5c7e62f 100644
--- a/src/service.c
+++ b/src/service.c
@@ -843,7 +843,7 @@ static int service_load_sysv_path(Service *s, const char 
*path) {
 
 /* Special setting for all SysV services */
 s-type = SERVICE_FORKING;
-s-remain_after_exit = true;
+s-remain_after_exit = !s-pid_file;
 s-restart = SERVICE_RESTART_NO;
 s-exec_context.std_output =
 (s-meta.manager-sysv_console || s-exec_context.std_input == 
EXEC_INPUT_TTY)


___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2011-07-01 Thread Steven Dake
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.

Signed-off-by: Steven Dake sd...@redhat.com
---
 src/systemctl.c |6 --
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/systemctl.c b/src/systemctl.c
index f6dca5b..93f4fda 100644
--- a/src/systemctl.c
+++ b/src/systemctl.c
@@ -2614,9 +2614,11 @@ static int show_one(const char *verb, DBusConnection 
*bus, const char *path, boo
 if (!show_properties)
 print_status_info(info);
 
-if (!streq_ptr(info.active_state, active) 
+if ((!streq_ptr(info.active_state, active) 
 !streq_ptr(info.active_state, reloading) 
-streq(verb, status))
+streq(verb, status)) ||
+(streq_ptr(info.active_state, active) 
+streq_ptr(info.sub_state, exited)))
 /* According to LSB: program not running */
 r = 3;
 
-- 
1.7.4.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2011-07-01 Thread Lennart Poettering
On Fri, 01.07.11 00:00, Steven Dake (sd...@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.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel