Skip to content

Commit 9227147

Browse files
authored
Merge pull request #472 from finit-project/reload-foo
2 parents 266f113 + 6047810 commit 9227147

File tree

7 files changed

+42
-6
lines changed

7 files changed

+42
-6
lines changed

doc/ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ All relevant changes are documented in this file.
1414
- Set USER and LOGNAME environment variables when dropping privileges.
1515
Fixes issues with software like rootless Podman that determines user
1616
identity from environment variables, by Aaron Andersen
17+
- Add `remain:yes` option for run/task oneshot commands, similar to the
18+
systemd `RemainAfterExit=yes`, by Aaron Andersen
19+
- Clear service conditions on `initctl reload NAME` to ensure dependent
20+
services are properly updated
1721

1822
### Fixes
1923
- Fix #464: invalid user:group examples in cgroups.md

doc/conditions.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ When Finit configuration files are changed and the `initctl reload`
194194
command is called, it is expected of services to touch their PID files
195195
for Finit to reassert their conditions.
196196

197+
Similarly, when a single service is reloaded with `initctl reload NAME`,
198+
its conditions are cleared and reasserted, ensuring dependent services
199+
are properly updated.
200+
197201
Daemons that don't create PID files, or fail to touch them on reload,
198202
can be worked around by using the `pid:/path/to/file.pid` syntax in
199203
the service stanza for the daemon. It is far from optimal since any

src/api.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ static int restart(svc_t *svc, void *user_data)
112112

113113
static int reload(svc_t *svc, void *user_data)
114114
{
115+
char cond[MAX_COND_LEN];
116+
115117
(void)user_data;
116118

117119
if (!svc)
@@ -122,6 +124,20 @@ static int reload(svc_t *svc, void *user_data)
122124
else
123125
service_timeout_cancel(svc);
124126

127+
/*
128+
* Clear conditions before reload to ensure dependent services
129+
* are properly updated. The conditions are reasserted when
130+
* the service touches its PID file after processing SIGHUP.
131+
*
132+
* Note: only clear 'ready' for services where the pidfile
133+
* inotify handler reasserts it (pid/none). For s6/systemd
134+
* services readiness relies on their respective notification
135+
* mechanism which may not re-trigger on SIGHUP.
136+
*/
137+
cond_clear(mkcond(svc, cond, sizeof(cond)));
138+
if (svc->notify == SVC_NOTIFY_PID || svc->notify == SVC_NOTIFY_NONE)
139+
service_ready(svc, 0);
140+
125141
svc_mark_dirty(svc);
126142
service_step(svc);
127143

src/sm.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,6 @@ void sm_step(void)
361361

362362
/* Restore terse mode and run hooks before shutdown */
363363
if (runlevel == 0 || runlevel == 6) {
364-
/* Hide cursor, we're going down ... */
365-
dprint(STDOUT_FILENO, "\033[?25l", 6);
366-
367364
api_exit();
368365
log_exit();
369366
plugin_run_hooks(HOOK_SHUTDOWN);

test/depserv.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# - bar must not start until foo is ready
66
# - bar must be stopped when foo goes down
77
# - bar must be restarted when foo is restarted
8+
# - bar must be restarted when foo is reloaded (per-service reload)
89
#
910
# Regression test bug #314, that bar is not in a restart loop when foo
1011
# is stopped. Also, verify that changing between runlevels, where foo
@@ -49,6 +50,13 @@ test_one()
4950
run "initctl status"
5051
assert "bar is restarted" "$(texec initctl |grep bar | awk '{print $1;}')" != "$pid"
5152

53+
say "Verify bar is restarted when foo is reloaded (per-service) ..."
54+
retry 'assert_status "bar" "running"' 5 1
55+
pid=$(texec initctl |grep bar | awk '{print $1;}')
56+
run "initctl reload foo"
57+
retry 'assert_status "bar" "running"' 5 1
58+
assert "bar is restarted on reload" "$(texec initctl |grep bar | awk '{print $1;}')" != "$pid"
59+
5260
# Wait for spice to be stolen by the Harkonnen
5361
sleep 3
5462
# bar should now have detected the loss of spice and be in restart
@@ -61,8 +69,9 @@ test_one()
6169
assert_status "bar" "waiting"
6270
}
6371

72+
run "initctl debug"
6473
sep
6574
test_one "pid/foo"
6675
sep
67-
run "initctl debug"
68-
test_one "service/foo/running"
76+
#run "initctl debug"
77+
test_one "service/foo/ready"

test/skel/bin/slay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ done
5252
echo "$pid" > /tmp/oldpid
5353

5454
#echo "PID $pid, kill -9 ..."
55-
kill -9 "$pid"
55+
kill -9 "$pid" 2>/dev/null || true

test/src/serv.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,12 @@ int main(int argc, char *argv[])
325325
#endif
326326
}
327327
}
328+
329+
if (melange) {
330+
mine(melange);
331+
vanish = -2;
332+
}
333+
328334
if (do_pidfile > 0)
329335
pidfile(NULL);
330336
reloading = 0;

0 commit comments

Comments
 (0)