Hi,
On Tue, 28 Aug 2012 20:42:52 +0200
Michael Biebl <[email protected]> wrote:
> We could extend that and check for the "Usage" message and set the
> Reload flag depending on wether we find a "reload" string in the help
> message.
Attached you can find a patch which does that (reviewed by mbiebl).
Before my patch, CanReload is always true:
$ systemctl show -p CanReload openarena-server.service
CanReload=yes
$ systemctl show -p CanReload pulseaudio.service
CanReload=yes
After adding it to the packaging, I get the following behavior:
$ systemctl show -p CanReload openarena-server.service
CanReload=no
$ systemctl show -p CanReload pulseaudio.service
CanReload=yes
The patch checks for '|reload[|}"]'. There is only one of 1187 init
scripts (provided by mbiebl, thanks!) which does not match this
expression but supports reload. There also are other scripts which
don’t come with a usage line (but support reload) or which have a more
complicated usage implementation (e.g. in a separate function).
Nevertheless, the patch should vastly improve the situation.
--
Best regards,
Michael
--- systemd-44.orig/src/service.c 2012-03-12 21:49:16.000000000 +0100
+++ systemd-44/src/service.c 2012-10-14 01:48:40.268064643 +0200
@@ -494,7 +494,7 @@
return c;
}
-static int sysv_exec_commands(Service *s) {
+static int sysv_exec_commands(Service *s, const bool supports_reload) {
ExecCommand *c;
assert(s);
@@ -508,9 +508,11 @@
return -ENOMEM;
exec_command_append_list(s->exec_command+SERVICE_EXEC_STOP, c);
- if (!(c = exec_command_new(s->sysv_path, "reload")))
- return -ENOMEM;
- exec_command_append_list(s->exec_command+SERVICE_EXEC_RELOAD, c);
+ if (supports_reload) {
+ if (!(c = exec_command_new(s->sysv_path, "reload")))
+ return -ENOMEM;
+ exec_command_append_list(s->exec_command+SERVICE_EXEC_RELOAD, c);
+ }
return 0;
}
@@ -528,6 +530,7 @@
} state = NORMAL;
char *short_description = NULL, *long_description = NULL, *chkconfig_description = NULL, *description;
struct stat st;
+ bool supports_reload = false;
assert(s);
assert(path);
@@ -574,8 +577,19 @@
line++;
t = strstrip(l);
- if (*t != '#')
+ if (*t != '#') {
+ /* Try to figure out whether this init script supports
+ * the reload operation. This heuristic looks for
+ * "Usage: " lines which include the reload option. */
+ if (strcasestr(t, "usage") &&
+ (strcasestr(t, "|reload|") ||
+ strcasestr(t, "|reload}") ||
+ strcasestr(t, "|reload\""))) {
+ supports_reload = true;
+ }
+
continue;
+ }
if (state == NORMAL && streq(t, "### BEGIN INIT INFO")) {
state = LSB;
@@ -868,7 +882,7 @@
}
}
- if ((r = sysv_exec_commands(s)) < 0)
+ if ((r = sysv_exec_commands(s, supports_reload)) < 0)
goto finish;
if (s->sysv_runlevels &&
chars_intersect(RUNLEVELS_BOOT, s->sysv_runlevels) &&