-rw-r--r-- | src/dudki.cc | 61 |
1 files changed, 39 insertions, 22 deletions
diff --git a/src/dudki.cc b/src/dudki.cc index b4e95a7..e91ad5e 100644 --- a/src/dudki.cc +++ b/src/dudki.cc @@ -63,10 +63,9 @@ int main(int argc,char **argv) { op_default, op_work, - op_hup, - op_term, - op_check, + op_signal, op_ensure, op_test } op = op_default; + int op_signum = 0; while(true) { #define SHORTOPTSTRING "f:hVLrkcet" @@ -94,5 +93,6 @@ int main(int argc,char **argv) { case 'h': cerr << PHEADER << endl - << PCOPY << endl << endl << + << PCOPY << endl << endl + << " " << argv[0] << " [options] [processes]" << endl << endl << #ifdef HAVE_GETOPT_LONG " -h, --help\n" @@ -103,7 +103,9 @@ int main(int argc,char **argv) { " specify the configuration file to use\n" "\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" " -t, --test test configuration file and exit" @@ -114,7 +116,9 @@ int main(int argc,char **argv) { " -f filename specify the configuration file to use\n" "\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" " -t test configuration file and exit" @@ -140,5 +144,5 @@ int main(int argc,char **argv) { exit(1); } - op = op_term; + op = op_signal; op_signum = SIGTERM; break; case 'r': @@ -147,5 +151,5 @@ int main(int argc,char **argv) { exit(1); } - op = op_hup; + op = op_signal; op_signum = SIGHUP; break; case 'c': @@ -154,5 +158,5 @@ int main(int argc,char **argv) { exit(1); } - op = op_check; + op = op_signal; op_signum = 0; break; case 'e': @@ -188,16 +192,29 @@ int main(int argc,char **argv) { cerr << "Configuration OK" << endl; 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); } case op_ensure: |