diff --git a/src/sbd-common.c b/src/sbd-common.c index 3abf75f..66489d1 100644 --- a/src/sbd-common.c +++ b/src/sbd-common.c @@ -1160,11 +1160,28 @@ sbd_cdtocoredir(void) return rc; } +void +sbd_detach(void) +{ + const char *devnull = "/dev/null"; + + maximize_priority(); + sysrq_init(); + + umask(022); + close(0); + (void)open(devnull, O_RDONLY); + close(1); + (void)open(devnull, O_WRONLY); + close(2); + (void)open(devnull, O_WRONLY); + sbd_cdtocoredir(); +} + pid_t make_daemon(void) { pid_t pid; - const char * devnull = "/dev/null"; pid = fork(); if (pid < 0) { @@ -1179,17 +1196,8 @@ make_daemon(void) qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_FALSE); /* This is the child; ensure privileges have not been lost. */ - maximize_priority(); - sysrq_init(); - - umask(022); - close(0); - (void)open(devnull, O_RDONLY); - close(1); - (void)open(devnull, O_WRONLY); - close(2); - (void)open(devnull, O_WRONLY); - sbd_cdtocoredir(); + sbd_detach(); + return 0; } diff --git a/src/sbd-inquisitor.c b/src/sbd-inquisitor.c index d917cd1..3266cfe 100644 --- a/src/sbd-inquisitor.c +++ b/src/sbd-inquisitor.c @@ -1387,7 +1387,14 @@ int main(int argc, char **argv, char **envp) cl_log(LOG_NOTICE, "%s flush + write \'%c\' to sysrq in case of timeout", do_flush?"Do":"Skip", timeout_sysrq_char); - exit_status = inquisitor(); + if (pidfile) { + exit_status = inquisitor(); + } else { + sbd_detach(); + inquisitor_child(); + /* not reached */ + exit(0); + } } else { exit_status = -2; } diff --git a/src/sbd.h b/src/sbd.h index bbdc6f1..b65fea2 100644 --- a/src/sbd.h +++ b/src/sbd.h @@ -136,6 +136,7 @@ void do_reset(void); void do_off(void); void do_timeout_action(void); pid_t make_daemon(void); +void sbd_detach(void); void maximize_priority(void); void sbd_get_uname(void); void sbd_set_format_string(int method, const char *daemon); diff --git a/src/sbd.service.in b/src/sbd.service.in index a558a67..eec688d 100644 --- a/src/sbd.service.in +++ b/src/sbd.service.in @@ -9,11 +9,16 @@ RefuseManualStop=true RefuseManualStart=true [Service] -Type=forking -PIDFile=@runstatedir@/sbd.pid +Type=simple +# sbd-inquisitor will usually have opened a watchdog-device +# thus we should give it a chance to do what +# it needs to (anyway kills the subprocesses the +# hard way) and close that gracefully. +# If that isn't successful within time let mixed +# do a cleanup although that will most likely lead to suicide. +KillMode=mixed EnvironmentFile=-@CONFIGDIR@/sbd -ExecStart=@sbindir@/sbd $SBD_OPTS -p @runstatedir@/sbd.pid watch -ExecStop=@bindir@/kill -TERM $MAINPID +ExecStart=@sbindir@/sbd $SBD_OPTS watch # Could this benefit from exit codes for restart? # Does this need to be set to msgwait * 1.2? diff --git a/src/sbd_remote.service.in b/src/sbd_remote.service.in index 56675b1..5c08784 100644 --- a/src/sbd_remote.service.in +++ b/src/sbd_remote.service.in @@ -7,11 +7,16 @@ RefuseManualStop=true RefuseManualStart=true [Service] -Type=forking -PIDFile=@runstatedir@/sbd.pid +Type=simple +# sbd-inquisitor will usually have opened a watchdog-device +# thus we should give it a chance to do what +# it needs to (anyway kills the subprocesses the +# hard way) and close that gracefully. +# If that isn't successful within time let mixed +# do a cleanup although that will most likely lead to suicide. +KillMode=mixed EnvironmentFile=-@CONFIGDIR@/sbd -ExecStart=@sbindir@/sbd $SBD_OPTS -p @runstatedir@/sbd.pid watch -ExecStop=@bindir@/kill -TERM $MAINPID +ExecStart=@sbindir@/sbd $SBD_OPTS watch # Could this benefit from exit codes for restart? # Does this need to be set to msgwait * 1.2?