author | Michael Krelin <hacker@klever.net> | 2004-07-23 20:40:46 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2004-07-23 20:40:46 (UTC) |
commit | 546858a1e4d13d179a6af27b474e1396cfdf0c29 (patch) (side-by-side diff) | |
tree | ac19b0ff5e4b3164ad5375bda112a9d6d2f88c2b | |
parent | 76921288a0aa39acb53102863523c388b5d0f9ee (diff) | |
download | dudki-546858a1e4d13d179a6af27b474e1396cfdf0c29.zip dudki-546858a1e4d13d179a6af27b474e1396cfdf0c29.tar.gz dudki-546858a1e4d13d179a6af27b474e1396cfdf0c29.tar.bz2 |
the ability to check/kill/reload any of the processes being monitored added.
-rw-r--r-- | man/dudki.8.in | 11 | ||||
-rw-r--r-- | src/dudki.cc | 61 | ||||
-rw-r--r-- | src/process.cc | 30 | ||||
-rw-r--r-- | src/process.h | 2 |
4 files changed, 65 insertions, 39 deletions
diff --git a/man/dudki.8.in b/man/dudki.8.in index 3011034..05db733 100644 --- a/man/dudki.8.in +++ b/man/dudki.8.in @@ -28,2 +28,3 @@ dudki \- a process monitoring daemon .if \*[longopt] [\fB--test\fR] +[\fI<process-list>\fR] @@ -47,3 +48,4 @@ Specify the configuration file to use (default is .el \fB-k\fR -Stop the running instance by sending the \fBSIGTERM\fR signal. +Stop the running instance by sending the \fBSIGTERM\fR signal. If no process +name specified on the command line, dudki kills his own running instance. .TP @@ -51,3 +53,5 @@ Stop the running instance by sending the \fBSIGTERM\fR signal. .el \fB-r\fR -Reload the running instance by sending the \fBSIGHUP\fR signal. +Reload the running instance by sending the \fBSIGHUP\fR signal. Like with +\fB-k\fR, if no process name specified on the command line, dudki sends +\fBSIGHUP\fR to his own running instance. .TP @@ -55,3 +59,4 @@ Reload the running instance by sending the \fBSIGHUP\fR signal. .el \fB-c\fR -Check if dudki is running. Exit with non-zero status if not. +Check if dudki is running. Exit with non-zero status if not. The same target +rules as in \fB-k\fR and \fB-r\fR apply here. .TP diff --git a/src/dudki.cc b/src/dudki.cc index b4e95a7..e91ad5e 100644 --- a/src/dudki.cc +++ b/src/dudki.cc @@ -64,5 +64,3 @@ int main(int argc,char **argv) { op_work, - op_hup, - op_term, - op_check, + op_signal, op_ensure, @@ -70,2 +68,3 @@ int main(int argc,char **argv) { } op = op_default; + int op_signum = 0; while(true) { @@ -95,3 +94,4 @@ int main(int argc,char **argv) { cerr << PHEADER << endl - << PCOPY << endl << endl << + << PCOPY << endl << endl + << " " << argv[0] << " [options] [processes]" << endl << endl << #ifdef HAVE_GETOPT_LONG @@ -104,5 +104,7 @@ int main(int argc,char **argv) { "\n" - " -k, --kill stop running instance\n" + " -k, --kill stop running instance (send SIGTERM)\n" " -r, --reload reload running instance (send SIGHUP)\n" - " -c, --check check if dudki is running\n" + " -c, --check check if the process is running\n" + " (the above commands operate on dudki itself if no\n" + " process name has been specified)\n" " -e, --ensure ensure that dudki is running\n" @@ -115,5 +117,7 @@ int main(int argc,char **argv) { "\n" - " -k stop running instance\n" + " -k stop running instance (send SIGTERM)\n" " -r reload running instance (send SIGHUP)\n" - " -c check if dudki is running\n" + " -c check if the process is running\n" + " (the above commands operate on dudki itself if no\n" + " process name has been specified)\n" " -e ensure that dudki is running\n" @@ -141,3 +145,3 @@ int main(int argc,char **argv) { } - op = op_term; + op = op_signal; op_signum = SIGTERM; break; @@ -148,3 +152,3 @@ int main(int argc,char **argv) { } - op = op_hup; + op = op_signal; op_signum = SIGHUP; break; @@ -155,3 +159,3 @@ int main(int argc,char **argv) { } - op = op_check; + op = op_signal; op_signum = 0; break; @@ -189,14 +193,27 @@ int main(int argc,char **argv) { break; - case op_hup: - signal_self(config,SIGHUP); - break; - case op_term: - signal_self(config,SIGTERM); - break; - case op_check: - try{ - signal_self(config,0); - exit(0); + case op_signal: + try { + if(optind>=argc) { + signal_self(config,op_signum); + }else{ + int failures = 0; + for(int narg=optind;narg<argc;narg++) { + try { + processes_t::const_iterator i = config.processes.find(argv[narg]); + if(i==config.processes.end()) + throw runtime_error("no such process configured"); + i->second.signal(op_signum); + }catch(exception& e) { + cerr << "dudki(" << argv[narg] << "): " << e.what() << endl; + failures++; + } + } + if(failures) + throw runtime_error("not all processes have been successfully signaled"); + } + if(!op_signum) + exit(0); }catch(exception& e) { - exit(1); + if(!op_signum) + exit(1); } diff --git a/src/process.cc b/src/process.cc index bfab311..1ffac9f 100644 --- a/src/process.cc +++ b/src/process.cc @@ -17,17 +17,6 @@ using namespace std; void process::check(const string& id,configuration& config) { - bool running = false; - ifstream pids(pidfile.c_str(),ios::in); - if(pids) { - pid_t pid = 0; - pids >> pid; - pids.close(); - if(pid) { - if(!kill(pid,0)) { - running = true; - } - } - } - if(running){ + try { + signal(0); patience = 0; - }else{ + }catch(exception& e) { if(patience>60) { // TODO: configurable @@ -187 +176,14 @@ void process::notify_mailto(const string& email,const string& id,const string& e } + +void process::signal(int signum) const { + ifstream pids(pidfile.c_str(),ios::in); + if(!pids) + throw runtime_error("no pidfile found"); + pid_t pid = 0; + pids >> pid; + pids.close(); + if(!pid) + throw runtime_error("no pid in pidfile"); + if(kill(pid,signum)) + throw runtime_error("failed to signal process"); +} diff --git a/src/process.h b/src/process.h index b6d7091..27ee049 100644 --- a/src/process.h +++ b/src/process.h @@ -31,2 +31,4 @@ class process { const string& description,configuration& config); + + void signal(int signum) const; }; |