mirror of
https://github.com/troglobit/finit.git
synced 2026-11-13 17:00:16 +00:00
Wait for post:script and cleanup:script before returning OK
This change introduces two new states for the big Finit state machine: runlevel-clean and reload-clean. Here Finit now waits for any post or cleanup script to finish before returning OK to the initctl command. Additionally, the service state machine has been updated to ensure a run/task/sysv/service calls any post or cleanup script before they are removed. A new 'dead' state for svc_t is introduced which any removed svc_t ends up in now instead of becing collected from 'halted' state. Signed-off-by: Joachim Wiberg <troglobit@gmail.com> Add cleanup:script support, runs at service removal Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
7 files changed
+124
-26
No files matched your search
@@ -107,6 +107,9 @@ static char *sm_status(sm_state_t state)
|
||||
case SM_BOOTSTRAP_STATE:
|
||||
return "bootstrap";
|
||||
|
||||
case SM_BOOTSTRAP_WAIT_STATE:
|
||||
return "bootstrap/wait";
|
||||
|
||||
case SM_RUNNING_STATE:
|
||||
return "running";
|
||||
|
||||
@@ -116,15 +119,20 @@ static char *sm_status(sm_state_t state)
|
||||
case SM_RUNLEVEL_WAIT_STATE:
|
||||
return "runlevel/wait";
|
||||
|
||||
case SM_RUNLEVEL_CLEAN_STATE:
|
||||
return "runlevel/clean";
|
||||
|
||||
case SM_RELOAD_CHANGE_STATE:
|
||||
return "reload/change";
|
||||
|
||||
case SM_RELOAD_WAIT_STATE:
|
||||
return "reload/wait";
|
||||
|
||||
default:
|
||||
return "unknown";
|
||||
case SM_RELOAD_CLEAN_STATE:
|
||||
return "reload/clean";
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
static char sm_runlevel(int lvl)
|
||||
@@ -319,6 +327,22 @@ restart:
|
||||
sm->in_teardown = 0;
|
||||
service_step_all(SVC_TYPE_ANY);
|
||||
|
||||
sm->state = SM_RUNLEVEL_CLEAN_STATE;
|
||||
break;
|
||||
|
||||
case SM_RUNLEVEL_CLEAN_STATE:
|
||||
/*
|
||||
* Wait for post:script or cleanup:script to be collected,
|
||||
* which moves the svc to HALTED or DEAD state. We will
|
||||
* be called by the service_monitor() on collect.
|
||||
*/
|
||||
svc = svc_clean_completed();
|
||||
if (svc) {
|
||||
dbg("Waiting to collect post/cleanup script for %s, cmd %s(%d) ...",
|
||||
svc_ident(svc, NULL, 0), svc->cmd, svc->pid);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Cleanup stale services */
|
||||
svc_clean_dynamic(service_unregister);
|
||||
|
||||
@@ -372,6 +396,22 @@ restart:
|
||||
dbg("Starting services after reconf ...");
|
||||
service_step_all(SVC_TYPE_ANY);
|
||||
|
||||
sm->state = SM_RELOAD_CLEAN_STATE;
|
||||
break;
|
||||
|
||||
case SM_RELOAD_CLEAN_STATE:
|
||||
/*
|
||||
* Wait for post:script or cleanup:script to be collected,
|
||||
* which moves the svc to HALTED or DEAD state. We will
|
||||
* be called by the service_monitor() on collect.
|
||||
*/
|
||||
svc = svc_clean_completed();
|
||||
if (svc) {
|
||||
dbg("Waiting to collect post/cleanup script for %s, cmd %s(%d) ...",
|
||||
svc_ident(svc, NULL, 0), svc->cmd, svc->pid);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Cleanup stale services */
|
||||
svc_clean_dynamic(service_unregister);
|
||||
|
||||
|
||||
Reference in new issue
Block a user