Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions doc/conditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);

Expand Down
3 changes: 0 additions & 3 deletions src/sm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 11 additions & 2 deletions test/depserv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"
2 changes: 1 addition & 1 deletion test/skel/bin/slay
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ done
echo "$pid" > /tmp/oldpid

#echo "PID $pid, kill -9 ..."
kill -9 "$pid"
kill -9 "$pid" 2>/dev/null || true
6 changes: 6 additions & 0 deletions test/src/serv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down