mirror of
https://github.com/troglobit/finit.git
synced 2026-11-06 15:51:03 +00:00
sm: handle reload event
Signed-off-by: Jonas Johansson <jonas.johansson@westermo.se>
This commit is contained in:
1 parent
60df2043ac
commit
29315090f9
3 files changed
+66
-36
No files matched your search
@@ -342,18 +342,7 @@ static int service_restart(svc_t *svc)
|
|||||||
static void service_reload_dynamic_finish(void)
|
static void service_reload_dynamic_finish(void)
|
||||||
{
|
{
|
||||||
in_dyn_teardown = 0;
|
in_dyn_teardown = 0;
|
||||||
|
sm_step(&sm);
|
||||||
/* Cleanup stale services */
|
|
||||||
svc_clean_dynamic(service_unregister);
|
|
||||||
|
|
||||||
_d("Starting services after reconf ...");
|
|
||||||
service_step_all(SVC_TYPE_SERVICE | SVC_TYPE_INETD);
|
|
||||||
|
|
||||||
_d("Calling reconf hooks ...");
|
|
||||||
plugin_run_hooks(HOOK_SVC_RECONF);
|
|
||||||
|
|
||||||
service_step_all(SVC_TYPE_SERVICE | SVC_TYPE_INETD);
|
|
||||||
_d("Reconfiguration done");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -365,23 +354,9 @@ static void service_reload_dynamic_finish(void)
|
|||||||
*/
|
*/
|
||||||
void service_reload_dynamic(void)
|
void service_reload_dynamic(void)
|
||||||
{
|
{
|
||||||
/* First reload all *.conf in /etc/finit.d/ */
|
|
||||||
conf_reload_dynamic();
|
|
||||||
|
|
||||||
/* Then, mark all affected service conditions as in-flux and
|
|
||||||
* let all affected services move to WAITING/HALTED */
|
|
||||||
_d("Stopping services services not allowed after reconf ...");
|
|
||||||
in_dyn_teardown = 1;
|
in_dyn_teardown = 1;
|
||||||
cond_reload();
|
sm_set_reload(&sm);
|
||||||
service_step_all(SVC_TYPE_SERVICE | SVC_TYPE_INETD);
|
sm_step(&sm);
|
||||||
|
|
||||||
/* Need to wait for any services to stop? If so, exit early
|
|
||||||
* and perform second stage from service_monitor later. */
|
|
||||||
if (!service_stop_is_done())
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* Otherwise, kick all svcs again right away */
|
|
||||||
service_reload_dynamic_finish();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include "finit.h"
|
#include "finit.h"
|
||||||
|
#include "cond.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "private.h"
|
#include "private.h"
|
||||||
@@ -38,6 +39,7 @@ void sm_init(sm_t *sm)
|
|||||||
{
|
{
|
||||||
sm->state = SM_BOOTSTRAP_STATE;
|
sm->state = SM_BOOTSTRAP_STATE;
|
||||||
sm->newlevel = -1;
|
sm->newlevel = -1;
|
||||||
|
sm->reload = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sm_set_runlevel(sm_t *sm, int newlevel)
|
void sm_set_runlevel(sm_t *sm, int newlevel)
|
||||||
@@ -45,6 +47,11 @@ void sm_set_runlevel(sm_t *sm, int newlevel)
|
|||||||
sm->newlevel = newlevel;
|
sm->newlevel = newlevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sm_set_reload(sm_t *sm)
|
||||||
|
{
|
||||||
|
sm->reload = 1;
|
||||||
|
}
|
||||||
|
|
||||||
char *sm_status(sm_t *sm)
|
char *sm_status(sm_t *sm)
|
||||||
{
|
{
|
||||||
switch (sm->state) {
|
switch (sm->state) {
|
||||||
@@ -54,8 +61,12 @@ char *sm_status(sm_t *sm)
|
|||||||
return "running";
|
return "running";
|
||||||
case SM_RUNLEVEL_CHANGE_STATE:
|
case SM_RUNLEVEL_CHANGE_STATE:
|
||||||
return "runlevel/change";
|
return "runlevel/change";
|
||||||
case SM_RUNLEVEL_WAIT_STOP_STATE:
|
case SM_RUNLEVEL_WAIT_STATE:
|
||||||
return "runlevel/wait";
|
return "runlevel/wait";
|
||||||
|
case SM_RELOAD_CHANGE_STATE:
|
||||||
|
return "reload/change";
|
||||||
|
case SM_RELOAD_WAIT_STATE:
|
||||||
|
return "reload/wait";
|
||||||
default:
|
default:
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
@@ -70,7 +81,7 @@ restart:
|
|||||||
|
|
||||||
_d("state: %s", sm_status(sm));
|
_d("state: %s", sm_status(sm));
|
||||||
|
|
||||||
switch(sm->state) {
|
switch (sm->state) {
|
||||||
case SM_BOOTSTRAP_STATE:
|
case SM_BOOTSTRAP_STATE:
|
||||||
_d("Bootstrapping all services in runlevel S from %s", FINIT_CONF);
|
_d("Bootstrapping all services in runlevel S from %s", FINIT_CONF);
|
||||||
service_step_all(SVC_TYPE_RUN | SVC_TYPE_TASK | SVC_TYPE_SERVICE);
|
service_step_all(SVC_TYPE_RUN | SVC_TYPE_TASK | SVC_TYPE_SERVICE);
|
||||||
@@ -87,6 +98,12 @@ restart:
|
|||||||
sm->state = SM_RUNLEVEL_CHANGE_STATE;
|
sm->state = SM_RUNLEVEL_CHANGE_STATE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
/* reload ? */
|
||||||
|
if (sm->reload) {
|
||||||
|
sm->reload = 0;
|
||||||
|
sm->state = SM_RELOAD_CHANGE_STATE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case SM_RUNLEVEL_CHANGE_STATE:
|
case SM_RUNLEVEL_CHANGE_STATE:
|
||||||
prevlevel = runlevel;
|
prevlevel = runlevel;
|
||||||
@@ -102,10 +119,10 @@ restart:
|
|||||||
_d("Stopping services services not allowed in new runlevel ...");
|
_d("Stopping services services not allowed in new runlevel ...");
|
||||||
service_step_all(SVC_TYPE_ANY);
|
service_step_all(SVC_TYPE_ANY);
|
||||||
|
|
||||||
sm->state = SM_RUNLEVEL_WAIT_STOP_STATE;
|
sm->state = SM_RUNLEVEL_WAIT_STATE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SM_RUNLEVEL_WAIT_STOP_STATE:
|
case SM_RUNLEVEL_WAIT_STATE:
|
||||||
/* Need to wait for any services to stop? If so, exit early
|
/* Need to wait for any services to stop? If so, exit early
|
||||||
* and perform second stage from service_monitor later. */
|
* and perform second stage from service_monitor later. */
|
||||||
if (!service_stop_is_done())
|
if (!service_stop_is_done())
|
||||||
@@ -143,6 +160,40 @@ restart:
|
|||||||
|
|
||||||
sm->state = SM_RUNNING_STATE;
|
sm->state = SM_RUNNING_STATE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SM_RELOAD_CHANGE_STATE:
|
||||||
|
/* First reload all *.conf in /etc/finit.d/ */
|
||||||
|
conf_reload_dynamic();
|
||||||
|
|
||||||
|
/* Then, mark all affected service conditions as in-flux and
|
||||||
|
* let all affected services move to WAITING/HALTED */
|
||||||
|
_d("Stopping services services not allowed after reconf ...");
|
||||||
|
cond_reload();
|
||||||
|
service_step_all(SVC_TYPE_SERVICE | SVC_TYPE_INETD);
|
||||||
|
|
||||||
|
sm->state = SM_RELOAD_WAIT_STATE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SM_RELOAD_WAIT_STATE:
|
||||||
|
/* Need to wait for any services to stop? If so, exit early
|
||||||
|
* and perform second stage from service_monitor later. */
|
||||||
|
if (!service_stop_is_done())
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Cleanup stale services */
|
||||||
|
svc_clean_dynamic(service_unregister);
|
||||||
|
|
||||||
|
_d("Starting services after reconf ...");
|
||||||
|
service_step_all(SVC_TYPE_SERVICE | SVC_TYPE_INETD);
|
||||||
|
|
||||||
|
_d("Calling reconf hooks ...");
|
||||||
|
plugin_run_hooks(HOOK_SVC_RECONF);
|
||||||
|
|
||||||
|
service_step_all(SVC_TYPE_SERVICE | SVC_TYPE_INETD);
|
||||||
|
_d("Reconfiguration done");
|
||||||
|
|
||||||
|
sm->state = SM_RUNNING_STATE;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sm->state != old_state) {
|
if (sm->state != old_state) {
|
||||||
|
|||||||
@@ -28,17 +28,21 @@ typedef enum {
|
|||||||
SM_BOOTSTRAP_STATE = 0,
|
SM_BOOTSTRAP_STATE = 0,
|
||||||
SM_RUNNING_STATE,
|
SM_RUNNING_STATE,
|
||||||
SM_RUNLEVEL_CHANGE_STATE,
|
SM_RUNLEVEL_CHANGE_STATE,
|
||||||
SM_RUNLEVEL_WAIT_STOP_STATE,
|
SM_RUNLEVEL_WAIT_STATE,
|
||||||
|
SM_RELOAD_CHANGE_STATE,
|
||||||
|
SM_RELOAD_WAIT_STATE,
|
||||||
} sm_state_t;
|
} sm_state_t;
|
||||||
|
|
||||||
typedef struct sm {
|
typedef struct sm {
|
||||||
sm_state_t state;
|
sm_state_t state;
|
||||||
int newlevel;
|
int newlevel;
|
||||||
|
int reload;
|
||||||
} sm_t;
|
} sm_t;
|
||||||
|
|
||||||
void sm_init(sm_t *sm);
|
void sm_init(sm_t *sm);
|
||||||
void sm_step(sm_t *sm);
|
void sm_step(sm_t *sm);
|
||||||
void sm_set_runlevel(sm_t *sm, int newlevel);
|
void sm_set_runlevel(sm_t *sm, int newlevel);
|
||||||
|
void sm_set_reload(sm_t *sm);
|
||||||
|
|
||||||
#endif /* FINIT_SM_H_ */
|
#endif /* FINIT_SM_H_ */
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user