Add reset interval after which restart interval is reset

This commit is contained in:
C. McEnroe 2020-08-15 18:25:40 -04:00
parent a2c5773b03
commit 497cafbf0f
4 changed files with 30 additions and 12 deletions

View File

@ -1,4 +1,4 @@
.Dd August 13, 2020
.Dd August 15, 2020
.Dt CATSITD 8
.Os
.
@ -14,8 +14,9 @@
.Op Fl f Ar config
.Op Fl g Ar group
.Op Fl p Ar pidfile
.Op Fl r Ar reset
.Op Fl s Ar stopexits
.Op Fl t Ar interval
.Op Fl t Ar restart
.Op Fl u Ar user
.
.Sh DESCRIPTION
@ -100,6 +101,13 @@ Write the PID of the
process to
.Ar pidfile .
.
.It Fl r Ar reset
Set the interval in milliseconds
for which a process must live
to have its service restart interval
reset to the initial value.
The default interval is 15 minutes.
.
.It Fl s Ar stopexits
Set the list of exit statuses
for which a restart will not be attempted.
@ -118,10 +126,10 @@ defined in
The exit status 127
is always treated as a stop exit.
.
.It Fl t Ar interval
.It Fl t Ar restart
Set the initial interval between restarts
in milliseconds.
The default interval is 1000.
The default interval is 1 second.
.
.It Fl u Ar user
Change user to

View File

@ -48,8 +48,9 @@
#define WS " \t"
struct timespec restartInterval = { .tv_sec = 1 };
struct Set256 stopExits;
struct timespec restartInterval = { .tv_sec = 1 };
struct timespec resetInterval = { .tv_sec = 15 * 60 };
static volatile sig_atomic_t signals[NSIG];
static void signalHandler(int signal) {
@ -176,10 +177,10 @@ static void parseExits(char *list) {
}
}
static void parseInterval(const char *millis) {
static void parseInterval(struct timespec *interval, const char *millis) {
unsigned long ms = strtoul(millis, NULL, 10);
restartInterval.tv_sec = ms / 1000;
restartInterval.tv_nsec = 1000000 * (ms % 1000);
interval->tv_sec = ms / 1000;
interval->tv_nsec = 1000000 * (ms % 1000);
}
static void setTitle(void) {
@ -208,7 +209,7 @@ int main(int argc, char *argv[]) {
const char *userName = NULL;
const char *groupName = NULL;
for (int opt; 0 < (opt = getopt(argc, argv, "C:c:df:g:p:s:t:u:"));) {
for (int opt; 0 < (opt = getopt(argc, argv, "C:c:df:g:p:r:s:t:u:"));) {
switch (opt) {
break; case 'C': serviceDir = optarg;
break; case 'c': fifoPath = optarg;
@ -216,8 +217,9 @@ int main(int argc, char *argv[]) {
break; case 'f': configPath = optarg;
break; case 'g': groupName = optarg;
break; case 'p': pidPath = optarg;
break; case 'r': parseInterval(&resetInterval, optarg);
break; case 's': parseExits(optarg);
break; case 't': parseInterval(optarg);
break; case 't': parseInterval(&restartInterval, optarg);
break; case 'u': userName = optarg;
break; default: return EX_USAGE;
}

View File

@ -119,6 +119,7 @@ struct Service {
int errPipe[2];
struct Line outLine;
struct Line errLine;
struct timespec startTime;
struct timespec restartInterval;
struct timespec restartDeadline;
};
@ -156,3 +157,4 @@ static inline uint32_t setTest(const struct Set256 *set, byte x) {
enum { StopExit = 127 };
extern struct Set256 stopExits;
extern struct timespec restartInterval;
extern struct timespec resetInterval;

View File

@ -163,8 +163,9 @@ void serviceStart(struct Service *service) {
return;
}
if (service->pid) {
syslog(LOG_NOTICE, "%s[%d] started", service->name, service->pid);
service->state = Start;
clock_gettime(CLOCK_MONOTONIC, &service->startTime);
syslog(LOG_NOTICE, "%s[%d] started", service->name, service->pid);
return;
}
@ -282,7 +283,12 @@ void serviceReap(pid_t pid, int status) {
}
if (service->intent == Start) {
// TODO: Determine if restart interval should be reset?
struct timespec uptime;
clock_gettime(CLOCK_MONOTONIC, &uptime);
timespecsub(&uptime, &service->startTime, &uptime);
if (timespeccmp(&uptime, &resetInterval, >=)) {
service->restartInterval = restartInterval;
}
setDeadline(service);
syslog(
LOG_NOTICE, "%s[%d] restarting in %lds",