mirror of
https://github.com/troglobit/finit.git
synced 2026-10-31 13:00:32 +00:00
Allow tty's to always respawn, no max restart count
This patch adds a `respawn` flag for services and ttys, always set for ttys, that allows bypassing the crash/restart counter and immediately restart a 'crashing' service. For tty type services this is the expected behavior, but for regular services it is not. That is why `respawn` flags is not advertised in the docs. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
ed9590aef1
commit
a19b82ea5f
2 files changed
+15
-2
No files matched your search
+14
-2
@@ -1123,6 +1123,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
|||||||
char *pre_script = NULL, *post_script = NULL;
|
char *pre_script = NULL, *post_script = NULL;
|
||||||
struct tty tty = { 0 };
|
struct tty tty = { 0 };
|
||||||
char *dev = NULL;
|
char *dev = NULL;
|
||||||
|
int respawn = 0;
|
||||||
int levels = 0;
|
int levels = 0;
|
||||||
int manual = 0;
|
int manual = 0;
|
||||||
char *line;
|
char *line;
|
||||||
@@ -1182,6 +1183,8 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
|||||||
name = cmd;
|
name = cmd;
|
||||||
else if (!strncasecmp(cmd, "manual:yes", 10))
|
else if (!strncasecmp(cmd, "manual:yes", 10))
|
||||||
manual = 1;
|
manual = 1;
|
||||||
|
else if (!strncasecmp(cmd, "respawn", 7))
|
||||||
|
respawn = 1;
|
||||||
else if (!strncasecmp(cmd, "halt:", 5))
|
else if (!strncasecmp(cmd, "halt:", 5))
|
||||||
halt = &cmd[5];
|
halt = &cmd[5];
|
||||||
else if (!strncasecmp(cmd, "kill:", 5))
|
else if (!strncasecmp(cmd, "kill:", 5))
|
||||||
@@ -1242,6 +1245,9 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
|||||||
dev = tty_atcon();
|
dev = tty_atcon();
|
||||||
else
|
else
|
||||||
dev = tty.dev;
|
dev = tty.dev;
|
||||||
|
|
||||||
|
/* tty's always respawn, never incr. restart_cnt */
|
||||||
|
respawn = 1;
|
||||||
next:
|
next:
|
||||||
svc = svc_find_by_tty(dev);
|
svc = svc_find_by_tty(dev);
|
||||||
} else
|
} else
|
||||||
@@ -1348,6 +1354,8 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
|||||||
parse_env(svc, env);
|
parse_env(svc, env);
|
||||||
if (file)
|
if (file)
|
||||||
strlcpy(svc->file, file, sizeof(svc->file));
|
strlcpy(svc->file, file, sizeof(svc->file));
|
||||||
|
if (respawn)
|
||||||
|
svc->respawn = 1;
|
||||||
|
|
||||||
/* Set configured limits */
|
/* Set configured limits */
|
||||||
memcpy(svc->rlimit, rlimit, sizeof(svc->rlimit));
|
memcpy(svc->rlimit, rlimit, sizeof(svc->rlimit));
|
||||||
@@ -1568,11 +1576,15 @@ static void service_retry(svc_t *svc)
|
|||||||
char *restart_cnt = (char *)&svc->restart_cnt;
|
char *restart_cnt = (char *)&svc->restart_cnt;
|
||||||
|
|
||||||
service_timeout_cancel(svc);
|
service_timeout_cancel(svc);
|
||||||
|
if (svc->respawn) {
|
||||||
|
_d("%s crashed, respawning ...", svc->cmd);
|
||||||
|
svc_unblock(svc);
|
||||||
|
service_step(svc);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (svc->state != SVC_HALTED_STATE ||
|
if (svc->state != SVC_HALTED_STATE ||
|
||||||
svc->block != SVC_BLOCK_RESTARTING) {
|
svc->block != SVC_BLOCK_RESTARTING) {
|
||||||
if (!svc_is_tty(svc))
|
|
||||||
_d("%s not crashing anymore", svc->cmd);
|
|
||||||
*restart_cnt = 0;
|
*restart_cnt = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,6 +127,7 @@ typedef struct svc {
|
|||||||
|
|
||||||
/* Counters */
|
/* Counters */
|
||||||
char once; /* run/task, (at least) once per runlevel */
|
char once; /* run/task, (at least) once per runlevel */
|
||||||
|
char respawn; /* ttys, or services with `respawn`, never increment restart_cnt */
|
||||||
const char restart_cnt; /* Incremented for each restart by service monitor. */
|
const char restart_cnt; /* Incremented for each restart by service monitor. */
|
||||||
|
|
||||||
union {
|
union {
|
||||||
|
|||||||
Reference in new issue
Block a user