/[monit]/monit/monitor.c
ViewVC logotype

Diff of /monit/monitor.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.23 by hauk, Sun Nov 3 08:43:50 2002 UTC revision 1.24 by hauk, Tue Nov 5 12:22:01 2002 UTC
# Line 136  static void do_init() { Line 136  static void do_init() {
136     * process data     * process data
137     */     */
138    status= pthread_mutex_init(&Run.mutex, NULL);    status= pthread_mutex_init(&Run.mutex, NULL);
139    if ( status != 0 ) {    if(status != 0) {
140            
141      error("%s: Cannot initialize mutex -- %s\n", prog, strerror(status));      error("%s: Cannot initialize mutex -- %s\n", prog, strerror(status));
142      exit(1);      exit(1);
# Line 146  static void do_init() { Line 146  static void do_init() {
146    /*    /*
147     * Get the position of the control file     * Get the position of the control file
148     */     */
149    if ( ! Run.controlfile ) {    if(! Run.controlfile) {
150            
151      Run.controlfile= find_rcfile();      Run.controlfile= find_rcfile();
152            
# Line 162  static void do_init() { Line 162  static void do_init() {
162     * any Runtime constants defined in the controlfile.     * any Runtime constants defined in the controlfile.
163     */     */
164    
165    if ( ! parse(Run.controlfile) ) {    if(! parse(Run.controlfile)) {
166            
167      exit(1);      exit(1);
168            
# Line 171  static void do_init() { Line 171  static void do_init() {
171    /*    /*
172     * Initialize the log system     * Initialize the log system
173     */     */
174    if ( ! log_init() ) {    if(! log_init()) {
175            
176      exit(1);      exit(1);
177            
# Line 180  static void do_init() { Line 180  static void do_init() {
180    /*    /*
181     * Did we find any process ?       * Did we find any process ?  
182     */     */
183    if ( ! processlist ) {    if(! processlist) {
184            
185      error("%s: No programs have been specified\n", prog);      error("%s: No programs have been specified\n", prog);
186      exit(0);      exit(0);
# Line 195  static void do_init() { Line 195  static void do_init() {
195    /*    /*
196     * Should we print debug information ?     * Should we print debug information ?
197     */     */
198    if ( Run.debug && have_tty ) {    if(Run.debug && have_tty) {
199            
200      printrunlist();      printrunlist();
201      printprocesslist();      printprocesslist();
# Line 218  static void do_reinit() { Line 218  static void do_reinit() {
218    /* Run the garbage collector */    /* Run the garbage collector */
219    gc();    gc();
220    
221    if ( ! parse(Run.controlfile) ) {    if(! parse(Run.controlfile)) {
222            
223      log("%s daemon died\n", prog);      log("%s daemon died\n", prog);
224      exit(1);      exit(1);
# Line 229  static void do_reinit() { Line 229  static void do_reinit() {
229    log_close();    log_close();
230    
231    /* Reinstall the log system */    /* Reinstall the log system */
232    if ( ! log_init() ) {    if(! log_init()) {
233            
234      exit(1);      exit(1);
235            
236    }    }
237    
238    /* Did we find any process ?  */    /* Did we find any process ?  */
239    if ( ! processlist ) {    if(! processlist) {
240            
241      error("%s: No programs have been specified\n", prog);      error("%s: No programs have been specified\n", prog);
242      exit(0);      exit(0);
# Line 257  static void do_action(char **args) { Line 257  static void do_action(char **args) {
257    char *action= args[optind];    char *action= args[optind];
258    char *P= args[++optind];    char *P= args[++optind];
259        
260    if( ! action ) {    if(! action) {
261            
262      do_default();      do_default();
263            
264    }    } else if(is(action, "start")) {
   else if( is(action, "start") ) {  
265            
266      if ( P ) check_process(P, "start"); else      if(P)
267         if ( mygroup ) control_group(mygroup, "start"); else control("start");          check_process(P, "start");
268        else {
269          
270          if(mygroup)
271              control_group(mygroup, "start");
272          else
273              control("start");
274        }
275        
276    }    } else if(is(action, "stop")) {
   else if( is(action, "stop") ) {  
277            
278      if ( P ) check_process(P, "stop"); else      if(P)
279         if ( mygroup ) control_group(mygroup, "stop"); else control("stop");          check_process(P, "stop");
280        else {
281          
282          if(mygroup)
283              control_group(mygroup, "stop");
284          else
285              control("stop");
286        }
287            
288    }    } else if(is(action, "restart")) {
   else if( is(action, "restart") ) {  
289            
290      if ( P ) {      if(P) {
291                
292        if ( ! exist_process(P) ) {        if(! exist_process(P)) {
293                    
294          error("%s: Cannot restart program '%s' -- not found in %s\n",          error("%s: Cannot restart program '%s' -- not found in %s\n",
295                prog, P, Run.controlfile);                prog, P, Run.controlfile);
# Line 289  static void do_action(char **args) { Line 300  static void do_action(char **args) {
300                
301        check_process(P, "stop");        check_process(P, "stop");
302                
303      } else      } else {
304          if ( mygroup ) control_group(mygroup, "stop"); else control("stop");        
305          if(mygroup)
306              control_group(mygroup, "stop");
307          else
308              control("stop");
309        }
310            
311      do_wait();      do_wait();
312            
313      if ( P ) check_process(P, "start"); else      if(P)
314         if ( mygroup ) control_group(mygroup, "start"); else control("start");          check_process(P, "start");
315        else {
316          
317          if(mygroup)
318              control_group(mygroup, "start");
319          else
320              control("start");
321        }
322            
323    }    } else if(is(action, "status")) {
   else if( is(action, "status") ) {  
324            
325      if ( mygroup ) status_group(mygroup); else status();      if(mygroup)
326            status_group(mygroup);
327        else
328            status();
329            
330    }    } else if(is(action, "quit")) {
   else if( is(action, "quit") ) {  
331            
332      log("Stopping monit daemon\n", prog);      log("Stopping monit daemon\n", prog);
333      kill_daemon();      kill_daemon();
334            
335    }    } else if(is(action, "validate")) {
   else if( is(action, "validate") ) {  
336            
337      validate();      validate();
338            
339    }    } else {
   else {  
340            
341      error("%s: invalid argument -- %s  (-h will show valid arguments)\n",      error("%s: invalid argument -- %s  (-h will show valid arguments)\n",
342            prog, action);            prog, action);
# Line 345  static int do_wakeupcall() { Line 367  static int do_wakeupcall() {
367    
368    pid_t pid;    pid_t pid;
369        
370    if ( (pid= exist_daemon()) > 0 ) {    if((pid= exist_daemon()) > 0) {
371            
372      kill(pid, SIGUSR1);      kill(pid, SIGUSR1);
373      error("%s daemon at %d awakened\n", prog, pid);      error("%s daemon at %d awakened\n", prog, pid);
# Line 364  static int do_wakeupcall() { Line 386  static int do_wakeupcall() {
386   */   */
387  static RETSIGTYPE do_destroy(int sig) {  static RETSIGTYPE do_destroy(int sig) {
388        
389    switch ( sig ) {    switch(sig) {
390            
391    case SIGTERM:    case SIGTERM:
392                
393        stop_http();        stop_http();
394                
395        if ( Run.isdaemon ) {        if(Run.isdaemon) {
396                    
397          log("%s daemon with pid [%d] killed\n", prog, (int)getpid());          log("%s daemon with pid [%d] killed\n", prog, (int)getpid());
398                    
# Line 397  static RETSIGTYPE do_destroy(int sig) { Line 419  static RETSIGTYPE do_destroy(int sig) {
419   */   */
420  static void do_default() {  static void do_default() {
421    
422    if ( Run.isdaemon ) {    if(Run.isdaemon) {
423            
424      if ( do_wakeupcall() ) {      if(do_wakeupcall()) {
425                
426        exit(0);        exit(0);
427                
428      }      }
429        
430      log("Starting %s daemon\n", prog);      log("Starting %s daemon\n", prog);
431      if(!Run.debug) printf("Starting %s daemon\n", prog);      if(! Run.debug) printf("Starting %s daemon\n", prog);
432            
433      if ( can_http() ) {      if(can_http()) {
434                
435        printf("Starting httpd at port [%d]\n", Run.httpdport);        printf("Starting httpd at port [%d]\n", Run.httpdport);
436                
437      }      }
438          
439      have_tty= FALSE;      if(Run.init != TRUE)
   
     if (Run.init != TRUE)  
440          daemonize();          daemonize();
441            
442      if ( !create_pidfile(Run.pidfile) ) {      if(! create_pidfile(Run.pidfile)) {
443                
444        log("%s daemon died\n", prog);        log("%s daemon died\n", prog);
445        exit(1);        exit(1);
446                
447      }      }
448    
449      if ( can_http() ) {      if(can_http()) {
450    
451        start_http();        start_http();
452                
453      }      }
454            
455      for (;;) {      for(;;) {
456                
457        if (Run.validate != TRUE)        if(Run.validate != TRUE) {
458          {          validate();
459            validate();        } else {
460          } else {          Run.validate= FALSE;
461            Run.validate= FALSE;        }
         }  
462    
463        sleep(Run.polltime);        sleep(Run.polltime);
464                
465        if ( is_rcfile_changed() ) {        if(is_rcfile_changed()) {
466                    
467          int port= Run.httpdport;          int port= Run.httpdport;
468    
469          do_reinit();          do_reinit();
470                    
471          if ( ! can_http() ) {          if(! can_http()) {
472                        
473            stop_http();            stop_http();
474                        
475          } else if ( port != Run.httpdport ) {          } else if (port != Run.httpdport) {
476                        
477            stop_http();            stop_http();
478            start_http();            start_http();
479                        
480          } else if ( ! check_httpd() ) {          } else if(! check_httpd()) {
481    
482            start_http();            start_http();
483              
484          }          }
485            
486        }        }
487                
488      }      }
# Line 500  static void handle_options(int argc, cha Line 519  static void handle_options(int argc, cha
519      case 'd':      case 'd':
520          Run.isdaemon= TRUE;          Run.isdaemon= TRUE;
521          sscanf(optarg, "%d", &Run.polltime);          sscanf(optarg, "%d", &Run.polltime);
522          if (Run.polltime<1) {          if(Run.polltime<1) {
523            error("%s: option -%c requires a natural number\n", prog, opt);            error("%s: option -%c requires a natural number\n", prog, opt);
524            exit(1);            exit(1);
525          }          }
# Line 512  static void handle_options(int argc, cha Line 531  static void handle_options(int argc, cha
531                    
532      case 'l':      case 'l':
533          Run.logfile= xstrdup(optarg);          Run.logfile= xstrdup(optarg);
534          if ( is(Run.logfile, "syslog") )          if(is(Run.logfile, "syslog"))
535              Run.use_syslog= TRUE;              Run.use_syslog= TRUE;
536          Run.dolog= TRUE;          Run.dolog= TRUE;
537          break;          break;
# Line 540  static void handle_options(int argc, cha Line 559  static void handle_options(int argc, cha
559          break;          break;
560                    
561      case '?':      case '?':
562          switch ( optopt ) {          switch(optopt) {
563                        
564          case 'c':          case 'c':
565          case 'd':          case 'd':
# Line 611  static void do_wait() { Line 630  static void do_wait() {
630        
631    int i;    int i;
632    
633    if ( have_tty ) {    if(have_tty) {
634            
635      fprintf(stdout, "Please wait for restart: ");      fprintf(stdout, "Please wait for restart: ");
636            
637      for (i= 0; i<10; i++) {      for(i= 0; i<10; i++) {
638                
639        fprintf(stdout, "."); fflush(stdout);        fprintf(stdout, "%c\b", "|/-\\"[i%4]);
640          fflush(stdout);
641        sleep(1);        sleep(1);
642                
643      }      }
644            
645      fprintf(stdout, "\n");      fprintf(stdout, " \n");
646            
647    } else {    } else {
648            

Legend:
Removed from v.1.23  
changed lines
  Added in v.1.24

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26