supervise-daemon: mark a service failed if it respawns too many times
This commit is contained in:
parent
1b5a3b4ef4
commit
ebf79db79e
@ -446,6 +446,7 @@ static void supervisor(char *exec, char **argv)
|
|||||||
char buf[2048];
|
char buf[2048];
|
||||||
char cmd[2048];
|
char cmd[2048];
|
||||||
int count;
|
int count;
|
||||||
|
int failing;
|
||||||
int health_status;
|
int health_status;
|
||||||
int healthcheck_respawn;
|
int healthcheck_respawn;
|
||||||
int i;
|
int i;
|
||||||
@ -498,6 +499,7 @@ static void supervisor(char *exec, char **argv)
|
|||||||
else if (healthchecktimer)
|
else if (healthchecktimer)
|
||||||
alarm(healthchecktimer);
|
alarm(healthchecktimer);
|
||||||
fifo_fd = open(fifopath, O_RDONLY |O_NONBLOCK);
|
fifo_fd = open(fifopath, O_RDONLY |O_NONBLOCK);
|
||||||
|
failing = 0;
|
||||||
while (!exiting) {
|
while (!exiting) {
|
||||||
healthcheck_respawn = 0;
|
healthcheck_respawn = 0;
|
||||||
wait_pid = waitpid(child_pid, &i, WNOHANG);
|
wait_pid = waitpid(child_pid, &i, WNOHANG);
|
||||||
@ -576,6 +578,7 @@ static void supervisor(char *exec, char **argv)
|
|||||||
syslog(LOG_WARNING, "respawned \"%s\" too many times, exiting",
|
syslog(LOG_WARNING, "respawned \"%s\" too many times, exiting",
|
||||||
exec);
|
exec);
|
||||||
exiting = 1;
|
exiting = 1;
|
||||||
|
failing = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ts.tv_sec = respawn_delay;
|
ts.tv_sec = respawn_delay;
|
||||||
@ -602,16 +605,18 @@ static void supervisor(char *exec, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (svcname) {
|
||||||
|
rc_service_daemon_set(svcname, exec, (const char *const *)argv,
|
||||||
|
pidfile, false);
|
||||||
|
rc_service_value_set(svcname, "child_pid", NULL);
|
||||||
|
rc_service_mark(svcname, RC_SERVICE_STOPPED);
|
||||||
|
if (failing)
|
||||||
|
rc_service_mark(svcname, RC_SERVICE_FAILED);
|
||||||
|
}
|
||||||
if (pidfile && exists(pidfile))
|
if (pidfile && exists(pidfile))
|
||||||
unlink(pidfile);
|
unlink(pidfile);
|
||||||
if (fifopath && exists(fifopath))
|
if (fifopath && exists(fifopath))
|
||||||
unlink(fifopath);
|
unlink(fifopath);
|
||||||
if (svcname) {
|
|
||||||
rc_service_daemon_set(svcname, exec, (const char *const *)argv,
|
|
||||||
pidfile, false);
|
|
||||||
rc_service_mark(svcname, RC_SERVICE_STOPPED);
|
|
||||||
rc_service_value_set(svcname, "child_pid", NULL);
|
|
||||||
}
|
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user