diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index c78b73bb..4057ff1f 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -14,6 +14,10 @@ All relevant changes are documented in this file. - Set USER and LOGNAME environment variables when dropping privileges. Fixes issues with software like rootless Podman that determines user identity from environment variables, by Aaron Andersen +- Add `remain:yes` option for run/task oneshot commands, similar to the + systemd `RemainAfterExit=yes`, by Aaron Andersen +- Clear service conditions on `initctl reload NAME` to ensure dependent + services are properly updated ### Fixes - Fix #464: invalid user:group examples in cgroups.md diff --git a/doc/conditions.md b/doc/conditions.md index a08a1cb7..93df4169 100644 --- a/doc/conditions.md +++ b/doc/conditions.md @@ -194,6 +194,10 @@ When Finit configuration files are changed and the `initctl reload` command is called, it is expected of services to touch their PID files for Finit to reassert their conditions. +Similarly, when a single service is reloaded with `initctl reload NAME`, +its conditions are cleared and reasserted, ensuring dependent services +are properly updated. + Daemons that don't create PID files, or fail to touch them on reload, can be worked around by using the `pid:/path/to/file.pid` syntax in the service stanza for the daemon. It is far from optimal since any diff --git a/src/api.c b/src/api.c index 381c2197..85373350 100644 --- a/src/api.c +++ b/src/api.c @@ -112,6 +112,8 @@ static int restart(svc_t *svc, void *user_data) static int reload(svc_t *svc, void *user_data) { + char cond[MAX_COND_LEN]; + (void)user_data; if (!svc) @@ -122,6 +124,20 @@ static int reload(svc_t *svc, void *user_data) else service_timeout_cancel(svc); + /* + * Clear conditions before reload to ensure dependent services + * are properly updated. The conditions are reasserted when + * the service touches its PID file after processing SIGHUP. + * + * Note: only clear 'ready' for services where the pidfile + * inotify handler reasserts it (pid/none). For s6/systemd + * services readiness relies on their respective notification + * mechanism which may not re-trigger on SIGHUP. + */ + cond_clear(mkcond(svc, cond, sizeof(cond))); + if (svc->notify == SVC_NOTIFY_PID || svc->notify == SVC_NOTIFY_NONE) + service_ready(svc, 0); + svc_mark_dirty(svc); service_step(svc); diff --git a/src/sm.c b/src/sm.c index a1e982b2..f23fa65a 100644 --- a/src/sm.c +++ b/src/sm.c @@ -361,9 +361,6 @@ void sm_step(void) /* Restore terse mode and run hooks before shutdown */ if (runlevel == 0 || runlevel == 6) { - /* Hide cursor, we're going down ... */ - dprint(STDOUT_FILENO, "\033[?25l", 6); - api_exit(); log_exit(); plugin_run_hooks(HOOK_SHUTDOWN); diff --git a/test/depserv.sh b/test/depserv.sh index 2f5c7a3c..9c0ebb73 100755 --- a/test/depserv.sh +++ b/test/depserv.sh @@ -5,6 +5,7 @@ # - bar must not start until foo is ready # - bar must be stopped when foo goes down # - bar must be restarted when foo is restarted +# - bar must be restarted when foo is reloaded (per-service reload) # # Regression test bug #314, that bar is not in a restart loop when foo # is stopped. Also, verify that changing between runlevels, where foo @@ -49,6 +50,13 @@ test_one() run "initctl status" assert "bar is restarted" "$(texec initctl |grep bar | awk '{print $1;}')" != "$pid" + say "Verify bar is restarted when foo is reloaded (per-service) ..." + retry 'assert_status "bar" "running"' 5 1 + pid=$(texec initctl |grep bar | awk '{print $1;}') + run "initctl reload foo" + retry 'assert_status "bar" "running"' 5 1 + assert "bar is restarted on reload" "$(texec initctl |grep bar | awk '{print $1;}')" != "$pid" + # Wait for spice to be stolen by the Harkonnen sleep 3 # bar should now have detected the loss of spice and be in restart @@ -61,8 +69,9 @@ test_one() assert_status "bar" "waiting" } +run "initctl debug" sep test_one "pid/foo" sep -run "initctl debug" -test_one "service/foo/running" +#run "initctl debug" +test_one "service/foo/ready" diff --git a/test/skel/bin/slay b/test/skel/bin/slay index 314ba1f3..d1c04efc 100755 --- a/test/skel/bin/slay +++ b/test/skel/bin/slay @@ -52,4 +52,4 @@ done echo "$pid" > /tmp/oldpid #echo "PID $pid, kill -9 ..." -kill -9 "$pid" +kill -9 "$pid" 2>/dev/null || true diff --git a/test/src/serv.c b/test/src/serv.c index dd9567e2..8129efb1 100644 --- a/test/src/serv.c +++ b/test/src/serv.c @@ -325,6 +325,12 @@ int main(int argc, char *argv[]) #endif } } + + if (melange) { + mine(melange); + vanish = -2; + } + if (do_pidfile > 0) pidfile(NULL); reloading = 0;