mirror of
https://github.com/troglobit/finit.git
synced 2026-10-19 11:09:35 +00:00
Fix #282: add support for oncrash:script to call post:script action
This patch adds the oncrash:script option to call the post:script action, if defined, for a crashing service. The EXIT_CODE variable sent to the script is set to `crashed`. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
278994781b
commit
5dd1a676ac
4 files changed
+41
-10
No files matched your search
+16
-1
@@ -1403,6 +1403,8 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
||||
else if (MATCH_CMD(cmd, "oncrash:", arg)) {
|
||||
if (MATCH_CMD(arg, "reboot", arg))
|
||||
oncrash_action = SVC_ONCRASH_REBOOT;
|
||||
if (MATCH_CMD(arg, "script", arg))
|
||||
oncrash_action = SVC_ONCRASH_SCRIPT;
|
||||
}
|
||||
else if (MATCH_CMD(cmd, "respawn", arg))
|
||||
respawn = 1;
|
||||
@@ -1868,6 +1870,9 @@ static void service_post_script(svc_t *svc)
|
||||
setenv("EXIT_STATUS", sig2str(sig), 1);
|
||||
}
|
||||
|
||||
if (svc_is_crashing(svc))
|
||||
setenv("EXIT_CODE", "crashed", 1);
|
||||
|
||||
execvp(_PATH_BSHELL, argv);
|
||||
_exit(EX_OSERR);
|
||||
}
|
||||
@@ -1945,10 +1950,20 @@ static void service_retry(svc_t *svc)
|
||||
svc_ident(svc, NULL, 0));
|
||||
svc_crashing(svc);
|
||||
*restart_cnt = 0;
|
||||
if (svc->oncrash_action == SVC_ONCRASH_REBOOT) {
|
||||
switch (svc->oncrash_action) {
|
||||
case SVC_ONCRASH_REBOOT:
|
||||
logit(LOG_ERR, "%s issuing reboot", svc_ident(svc, NULL, 0));
|
||||
sync();
|
||||
kill(1, SIGTERM);
|
||||
break;
|
||||
case SVC_ONCRASH_SCRIPT:
|
||||
if (svc_has_post(svc)) {
|
||||
dbg("calling post:script %s, crashing.", svc->post_script);
|
||||
service_post_script(svc);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
service_step(svc);
|
||||
return;
|
||||
|
||||
@@ -78,7 +78,8 @@ typedef enum {
|
||||
|
||||
typedef enum {
|
||||
SVC_ONCRASH_IGNORE = 0,
|
||||
SVC_ONCRASH_REBOOT = 1,
|
||||
SVC_ONCRASH_REBOOT,
|
||||
SVC_ONCRASH_SCRIPT,
|
||||
} svc_oncrash_action_t;
|
||||
|
||||
#define MAX_ID_LEN 16
|
||||
@@ -260,6 +261,7 @@ static inline int svc_is_updated (svc_t *svc) { return svc && 1 == svc->dirty
|
||||
static inline int svc_is_blocked (svc_t *svc) { return svc && svc->block != SVC_BLOCK_NONE; }
|
||||
static inline int svc_is_busy (svc_t *svc) { return svc && svc->block == SVC_BLOCK_BUSY; }
|
||||
static inline int svc_is_missing (svc_t *svc) { return svc && svc->block == SVC_BLOCK_MISSING; }
|
||||
static inline int svc_is_crashing (svc_t *svc) { return svc && svc->block == SVC_BLOCK_CRASHING; }
|
||||
|
||||
static inline void svc_unblock (svc_t *svc) { if (svc) svc->block = SVC_BLOCK_NONE; }
|
||||
#define svc_start(svc) svc_unblock(svc)
|
||||
|
||||
Reference in new issue
Block a user