diff --git a/src/initctl.c b/src/initctl.c index 3f2f3189..c65c4a12 100644 --- a/src/initctl.c +++ b/src/initctl.c @@ -756,7 +756,7 @@ static int show_status(char *arg) printf(" User : %s\n", svc->username); printf(" Group : %s\n", svc->group); printf(" Uptime : %s\n", svc->pid ? uptime(now - svc->start_time, uptm, sizeof(uptm)) : uptm); - printf(" Restarts : %d/%d\n", svc->restart_cnt, svc->restart_max); + printf(" Restarts : %d (%d/%d)\n", svc->restart_tot, svc->restart_cnt, svc->restart_max); printf(" Runlevels : %s\n", runlevel_string(runlevel, svc->runlevels)); if (cgrp && svc->pid > 1) { char grbuf[128]; diff --git a/src/service.c b/src/service.c index af90fcf8..0add643b 100644 --- a/src/service.c +++ b/src/service.c @@ -496,6 +496,12 @@ static int service_start(svc_t *svc) /* Declare we're waiting for svc to create its pidfile */ svc_starting(svc); + /* Increment total restarts, unless first time or non-service */ + if (svc_is_daemon(svc) || svc_is_sysv(svc)) { + if (svc->restart_cnt || svc->restart_tot) + svc->restart_tot++; + } + /* Block SIGCHLD while forking. */ sigemptyset(&nmask); sigaddset(&nmask, SIGCHLD); diff --git a/src/svc.h b/src/svc.h index bf647ba3..9f166d63 100644 --- a/src/svc.h +++ b/src/svc.h @@ -137,6 +137,7 @@ typedef struct svc { /* Counters */ char once; /* run/task, (at least) once per runlevel */ + unsigned int restart_tot; /* Total restarts ever, summarized, including `initctl restart` */ unsigned char restart_max; /* Maximum number of restarts allowed */ int restart_tmo; /* Time required for the service to start. */ unsigned char oncrash_action; /* Action to perform in crashed state. */