mirror of
https://github.com/troglobit/finit.git
synced 2026-10-25 12:04:36 +00:00
Assert svc condition only when PID file has been created/updated
This patch prevents too early start of services depending on other services. E.g, if service B depends on A then we must wait for A to signal that it is ready before we allow B to start -- in a Finit based system A does this by creating, or touching (updating mtime), its PID file. Services (like A) that support SIGHUP should call utime(), or utimensat(), on the PID file at the end of their SIGHUP handler. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
cef4b5761a
commit
4ae5c54f45
3 files changed
+22
-4
No files matched your search
+11
-4
@@ -44,13 +44,20 @@ static void pidfile_callback(void *UNUSED(arg), int fd, int UNUSED(events))
|
||||
|
||||
_d("%s: match %s", basename, svc->cmd);
|
||||
snprintf(cond, sizeof(cond), "svc%s", svc->cmd);
|
||||
if (ev->mask & (IN_CREATE | IN_ATTRIB))
|
||||
if (ev->mask & (IN_CREATE | IN_ATTRIB)) {
|
||||
svc_started(svc);
|
||||
cond_set(cond);
|
||||
else if (ev->mask & IN_DELETE)
|
||||
} else if (ev->mask & IN_DELETE)
|
||||
cond_clear(cond);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Assert condition only if the service is running, but not if it's
|
||||
* recently been changed or while it's starting up.
|
||||
*
|
||||
* We must wait for the service to create/touch its pidfile.
|
||||
*/
|
||||
static void pidfile_reconf(void *_null)
|
||||
{
|
||||
static char name[MAX_ARG_LEN];
|
||||
@@ -59,14 +66,14 @@ static void pidfile_reconf(void *_null)
|
||||
(void)(_null);
|
||||
|
||||
for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) {
|
||||
if (svc->state == SVC_RUNNING_STATE && !svc_is_changed(svc)) {
|
||||
if (svc->state == SVC_RUNNING_STATE && !svc_is_changed(svc) && !svc_is_starting(svc)) {
|
||||
snprintf(name, MAX_ARG_LEN, "svc%s", svc->cmd);
|
||||
cond_set_path(cond_path(name), COND_ON);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void pidfile_init (void *arg)
|
||||
static void pidfile_init(void *arg)
|
||||
{
|
||||
struct context *ctx = arg;
|
||||
|
||||
|
||||
Reference in new issue
Block a user