supervise-daemon: make respawn-max and respawn-period independent settings
This commit is contained in:
parent
77262c359c
commit
1b5a3b4ef4
@ -107,16 +107,19 @@ Data can be from 0 to 7 inclusive.
|
|||||||
.It Fl k , -umask Ar mode
|
.It Fl k , -umask Ar mode
|
||||||
Set the umask of the daemon.
|
Set the umask of the daemon.
|
||||||
.It Fl m , -respawn-max Ar count
|
.It Fl m , -respawn-max Ar count
|
||||||
Sets the maximum number of times a daemon will be respawned during a
|
Sets the maximum number of times a daemon will be respawned. If a daemon
|
||||||
respawn period. If a daemon dies more than this number of times during a
|
crashes more than this number of times,
|
||||||
respawn period,
|
|
||||||
.Nm
|
.Nm
|
||||||
will give up trying to respawn it and exit. The default is 10, and 0
|
will give up and exit. The default is 10 and 0 means unlimited.
|
||||||
means unlimited.
|
.Pp
|
||||||
|
If respawn-period is also set, more than respawn-max crashes must occur
|
||||||
|
during respawn-period seconds to cause
|
||||||
|
.Nm
|
||||||
|
to give up and exit.
|
||||||
.It Fl N , -nicelevel Ar level
|
.It Fl N , -nicelevel Ar level
|
||||||
Modifies the scheduling priority of the daemon.
|
Modifies the scheduling priority of the daemon.
|
||||||
.It Fl P , -respawn-period Ar seconds
|
.It Fl P , -respawn-period Ar seconds
|
||||||
Sets the length of a respawn period. The default is 10 seconds. See the
|
Sets the length of a respawn period. See the
|
||||||
description of --respawn-max for more information.
|
description of --respawn-max for more information.
|
||||||
.It Fl R , -retry Ar timeout | Ar signal Ns / Ns Ar timeout
|
.It Fl R , -retry Ar timeout | Ar signal Ns / Ns Ar timeout
|
||||||
The retry specification can be either a timeout in seconds or multiple
|
The retry specification can be either a timeout in seconds or multiple
|
||||||
|
@ -143,7 +143,7 @@ static pid_t child_pid;
|
|||||||
static int respawn_count = 0;
|
static int respawn_count = 0;
|
||||||
static int respawn_delay = 0;
|
static int respawn_delay = 0;
|
||||||
static int respawn_max = 10;
|
static int respawn_max = 10;
|
||||||
static int respawn_period = 5;
|
static int respawn_period = 0;
|
||||||
static char *fifopath = NULL;
|
static char *fifopath = NULL;
|
||||||
static int fifo_fd = 0;
|
static int fifo_fd = 0;
|
||||||
static char *pidfile = NULL;
|
static char *pidfile = NULL;
|
||||||
@ -563,23 +563,21 @@ static void supervisor(char *exec, char **argv)
|
|||||||
do_healthcheck = 0;
|
do_healthcheck = 0;
|
||||||
healthcheck_respawn = 0;
|
healthcheck_respawn = 0;
|
||||||
alarm(0);
|
alarm(0);
|
||||||
if (respawn_max > 0 && respawn_period > 0) {
|
respawn_now = time(NULL);
|
||||||
respawn_now = time(NULL);
|
if (first_spawn == 0)
|
||||||
if (first_spawn == 0)
|
first_spawn = respawn_now;
|
||||||
first_spawn = respawn_now;
|
if ((respawn_period > 0)
|
||||||
if (respawn_now - first_spawn > respawn_period) {
|
&& (respawn_now - first_spawn > respawn_period)) {
|
||||||
respawn_count = 0;
|
respawn_count = 0;
|
||||||
first_spawn = 0;
|
first_spawn = 0;
|
||||||
} else
|
} else
|
||||||
respawn_count++;
|
respawn_count++;
|
||||||
if (respawn_count > respawn_max) {
|
if (respawn_max > 0 && respawn_count > respawn_max) {
|
||||||
syslog(LOG_WARNING,
|
syslog(LOG_WARNING, "respawned \"%s\" too many times, exiting",
|
||||||
"respawned \"%s\" too many times, exiting", exec);
|
exec);
|
||||||
exiting = 1;
|
exiting = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
alarm(0);
|
|
||||||
ts.tv_sec = respawn_delay;
|
ts.tv_sec = respawn_delay;
|
||||||
ts.tv_nsec = 0;
|
ts.tv_nsec = 0;
|
||||||
nanosleep(&ts, NULL);
|
nanosleep(&ts, NULL);
|
||||||
@ -930,7 +928,7 @@ int main(int argc, char **argv)
|
|||||||
0, false, true) > 0)
|
0, false, true) > 0)
|
||||||
eerrorx("%s: %s is already running", applet, exec);
|
eerrorx("%s: %s is already running", applet, exec);
|
||||||
|
|
||||||
if (respawn_delay * respawn_max > respawn_period)
|
if (respawn_period > 0 && respawn_delay * respawn_max > respawn_period)
|
||||||
ewarn("%s: Please increase the value of --respawn-period to more "
|
ewarn("%s: Please increase the value of --respawn-period to more "
|
||||||
"than %d to avoid infinite respawning", applet,
|
"than %d to avoid infinite respawning", applet,
|
||||||
respawn_delay * respawn_max);
|
respawn_delay * respawn_max);
|
||||||
|
Loading…
Reference in New Issue
Block a user