void svc_monitor(pid_t lost) { svc_t *svc; if (was_stopped && !is_norespawn()) { was_stopped = 0; restart_any_lost_procs(); return; } if (fexist(SYNC_SHUTDOWN) || lost <= 1) return; /* Power user at the console, don't respawn tasks. */ if (is_norespawn()) { was_stopped = 1; return; } if (tty_respawn(lost)) return; #ifndef INETD_DISABLED if (inetd_respawn(lost)) return; #endif for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) { if (lost != svc->pid) continue; if (SVC_CMD_SERVICE != svc->type) { svc->pid = 0; continue; } _d("Ouch, lost pid %d - %s(%d)", lost, basename(svc->cmd), svc->pid); /* No longer running, update books. */ svc->pid = 0; if (sig_stopped()) { _e("Stopped, not respawning killed processes."); break; } /* Cleanup any lingering or semi-restarting tasks before respawning */ _d("Sending SIGTERM to service group %s", basename(svc->cmd)); procname_kill(basename(svc->cmd), SIGTERM); /* Restarting lost service. */ if (svc_enabled(svc, 0, NULL)) { svc->restart_counter++; svc_start(svc); } break; } }
void svc_monitor(void) { pid_t lost; svc_t *svc; lost = waitpid(-1, NULL, WNOHANG); if (lost < 1) return; if (fexist(SYNC_SHUTDOWN) || lost <= 1) return; /* Power user at the console, don't respawn tasks. */ if (is_norespawn()) return; for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) { char *name = basename(svc->cmd); if (lost != svc->pid) continue; _d("Ouch, lost pid %d - %s(%d)", lost, name, svc->pid); /* No longer running, update books. */ svc->pid = 0; if (sig_stopped()) { _e("Stopped, not respawning killed processes."); break; } /* Cleanup any lingering or semi-restarting tasks before respawning */ _d("Sending SIGTERM to service group %s", name); procname_kill(name, SIGTERM); /* Restarting lost service. */ if (svc_enabled(svc, 0, NULL)) { svc->stat_restart_counter++; svc_start(svc); } break; } }
static int is_norespawn(void) { return sig_stopped() || fexist("/mnt/norespawn") || fexist("/tmp/norespawn"); }
void service_monitor(pid_t lost) { svc_t *svc; static int was_stopped = 0; if (was_stopped && !is_norespawn()) { was_stopped = 0; restart_lost_procs(); return; } if (fexist(SYNC_SHUTDOWN) || lost <= 1) return; /* Power user at the console, don't respawn tasks. */ if (is_norespawn()) { was_stopped = 1; return; } if (tty_respawn(lost)) return; #ifndef INETD_DISABLED if (inetd_respawn(lost)) return; #endif for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) { if (lost != svc->pid) continue; if (SVC_TYPE_SERVICE != svc->type) { svc->pid = 0; continue; } _d("Ouch, lost pid %d - %s(%d)", lost, basename(svc->cmd), svc->pid); /* No longer running, update books. */ svc->pid = 0; if (sig_stopped()) { _e("Stopped, not respawning killed processes."); break; } /* Restarting lost service. */ if (service_enabled(svc, 0, NULL)) { if (svc->restart_counter > RESPAWN_MAX) { _e("Not restarting %s id %d, respawn MAX (%d) reached!", svc->cmd, svc->id, RESPAWN_MAX); break; } svc->restart_counter++; service_start(svc); } break; } }