author | Michael Krelin <hacker@klever.net> | 2004-07-24 00:24:07 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2004-07-24 00:24:07 (UTC) |
commit | fbc32792b8d8266ff90aa60403f5da78739236f4 (patch) (unidiff) | |
tree | 77bc3f196a3733c9c86290f8a73d60bb609bbdd5 /src/dudki.cc | |
parent | 125671c860a82643d36bc3da279d0b831fae4b34 (diff) | |
download | dudki-fbc32792b8d8266ff90aa60403f5da78739236f4.zip dudki-fbc32792b8d8266ff90aa60403f5da78739236f4.tar.gz dudki-fbc32792b8d8266ff90aa60403f5da78739236f4.tar.bz2 |
processes specified by process names (pidof-like).
-rw-r--r-- | src/dudki.cc | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/dudki.cc b/src/dudki.cc index 9562079..c966695 100644 --- a/src/dudki.cc +++ b/src/dudki.cc | |||
@@ -22,34 +22,36 @@ using namespace std; | |||
22 | #define PCOPY "Copyright (c) 2004 Klever Group" | 22 | #define PCOPY "Copyright (c) 2004 Klever Group" |
23 | 23 | ||
24 | bool finishing = false; | 24 | bool finishing = false; |
25 | bool restarting = false; | 25 | bool restarting = false; |
26 | static char **_argv = NULL; | 26 | static char **_argv = NULL; |
27 | 27 | ||
28 | static void lethal_signal_handler(int signum) { | 28 | static void lethal_signal_handler(int signum) { |
29 | syslog(LOG_NOTICE,"Lethal signal received. Terminating."); | 29 | syslog(LOG_NOTICE,"Lethal signal received. Terminating."); |
30 | finishing = true; | 30 | finishing = true; |
31 | } | 31 | } |
32 | static void sighup_handler(int signum) { | 32 | static void sighup_handler(int signum) { |
33 | syslog(LOG_NOTICE,"SUGHUP received, reloading."); | 33 | syslog(LOG_NOTICE,"SUGHUP received, reloading."); |
34 | restarting = finishing = true; | 34 | restarting = finishing = true; |
35 | } | 35 | } |
36 | 36 | ||
37 | void check_herd(configuration& config) { | 37 | void check_herd(configuration& config) { |
38 | process::prepare_herd(); | ||
38 | for(processes_t::iterator i=config.processes.begin();i!=config.processes.end();++i) | 39 | for(processes_t::iterator i=config.processes.begin();i!=config.processes.end();++i) |
39 | i->second.check(i->first,config); | 40 | i->second.check(i->first,config); |
41 | process::unprepare_herd(); | ||
40 | } | 42 | } |
41 | 43 | ||
42 | void signal_self(const configuration& config,int signum) { | 44 | void signal_self(const configuration& config,int signum) { |
43 | ifstream pids(config.pidfile.c_str(),ios::in); | 45 | ifstream pids(config.pidfile.c_str(),ios::in); |
44 | if(!pids) | 46 | if(!pids) |
45 | throw runtime_error("Can't detect running instance"); | 47 | throw runtime_error("Can't detect running instance"); |
46 | pid_t pid = 0; | 48 | pid_t pid = 0; |
47 | pids >> pid; | 49 | pids >> pid; |
48 | if(!pid) | 50 | if(!pid) |
49 | throw runtime_error("Can't detect running instance"); | 51 | throw runtime_error("Can't detect running instance"); |
50 | if(pid==getpid()) | 52 | if(pid==getpid()) |
51 | throw 0; | 53 | throw 0; |
52 | if(kill(pid,signum)) | 54 | if(kill(pid,signum)) |
53 | throw runtime_error("Failed to signal running instance"); | 55 | throw runtime_error("Failed to signal running instance"); |
54 | } | 56 | } |
55 | 57 | ||
@@ -207,33 +209,36 @@ int main(int argc,char **argv) { | |||
207 | config.parse(config_file); | 209 | config.parse(config_file); |
208 | switch(op) { | 210 | switch(op) { |
209 | case op_test: | 211 | case op_test: |
210 | cerr << "Configuration OK" << endl; | 212 | cerr << "Configuration OK" << endl; |
211 | break; | 213 | break; |
212 | case op_signal: | 214 | case op_signal: |
213 | try { | 215 | try { |
214 | if(optind>=argc) { | 216 | if(optind>=argc) { |
215 | signal_self(config,op_signum); | 217 | signal_self(config,op_signum); |
216 | }else{ | 218 | }else{ |
217 | int failures = 0; | 219 | int failures = 0; |
218 | for(int narg=optind;narg<argc;narg++) { | 220 | for(int narg=optind;narg<argc;narg++) { |
219 | try { | 221 | try { |
220 | processes_t::const_iterator i = config.processes.find(argv[narg]); | 222 | processes_t::const_iterator i = config.processes.find(argv[narg]); |
221 | if(i==config.processes.end()) | 223 | if(i==config.processes.end()) |
222 | throw runtime_error("no such process configured"); | 224 | throw runtime_error("no such process configured"); |
223 | i->second.signal(op_signum); | 225 | if(op_signum) |
226 | i->second.signal(op_signum); | ||
227 | else | ||
228 | i->second.check(); | ||
224 | }catch(exception& e) { | 229 | }catch(exception& e) { |
225 | cerr << "dudki(" << argv[narg] << "): " << e.what() << endl; | 230 | cerr << "dudki(" << argv[narg] << "): " << e.what() << endl; |
226 | failures++; | 231 | failures++; |
227 | } | 232 | } |
228 | } | 233 | } |
229 | if(failures) | 234 | if(failures) |
230 | throw runtime_error("not all processes have been successfully signaled"); | 235 | throw runtime_error("not all processes have been successfully signaled"); |
231 | } | 236 | } |
232 | if(!op_signum) | 237 | if(!op_signum) |
233 | exit(0); | 238 | exit(0); |
234 | }catch(exception& e) { | 239 | }catch(exception& e) { |
235 | if(!op_signum) | 240 | if(!op_signum) |
236 | exit(1); | 241 | exit(1); |
237 | } | 242 | } |
238 | case op_ensure: | 243 | case op_ensure: |
239 | try { | 244 | try { |