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

Diff of /monit/control.c

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

revision 1.25 by hauk, Thu Dec 19 20:50:06 2002 UTC revision 1.26 by hauk, Thu Dec 19 21:38:40 2002 UTC
# Line 43  Line 43 
43  /* Private Prototypes */  /* Private Prototypes */
44  static void do_stop(Process_T p);  static void do_stop(Process_T p);
45  static void do_start(Process_T p);  static void do_start(Process_T p);
46  static void do_restart_dependandt(Process_T p);  static void do_dependandt(Process_T p, char *action);
47    
48    
49  /**  /**
# Line 236  void check_process(char *P, char *action Line 236  void check_process(char *P, char *action
236        return;        return;
237      }      }
238            
239        do_dependandt(p, "stop");
240      do_start(p);      do_start(p);
241      do_restart_dependandt(p);      do_dependandt(p, "start");
242            
243    } else if(is(action, "stop")) {    } else if(is(action, "stop")) {
244            
# Line 358  static void do_stop(Process_T p) { Line 359  static void do_stop(Process_T p) {
359    
360    
361  /*  /*
362   * This is a pre-recursive function called after p was started and   * This is a pre-recursive function called before p is started for
363   * used to restart every process that depends on p, in reverse order.   * stopping every process that depends on p, in reverse order and
364     * after p was started to start every process that depends on p again.
365     * The action parametere controls if this function should start or
366     * stop the precceses that depend on p.
367   * @param p A Process_T object   * @param p A Process_T object
368     * @param action An action to do on the dependant processes
369   */   */
370  static void do_restart_dependandt(Process_T p) {  static void do_dependandt(Process_T p, char *action) {
371    
372    Process_T parent;    Process_T parent;
373    int max_tries= Run.polltime;    int max_tries= Run.polltime;
# Line 375  static void do_restart_dependandt(Proces Line 380  static void do_restart_dependandt(Proces
380                
381        Dependant_T d;        Dependant_T d;
382            
383        for(d= parent->dependantlist; d; d= d->next )        for(d= parent->dependantlist; d; d= d->next)
384            if(is(d->dependant, p->name))            if(is(d->dependant, p->name))
385                break;                break;
386        if(d && p->stop && p->start) {        if(d && p->stop && p->start) {
387          if(is_process_running(parent)) {  
388            log("stop: (%s) %s\n", parent->name, parent->stop->arg[0]);          if(is(action, "stop")) {
389            spawn(parent, parent->stop);            if(is_process_running(parent)) {
390            memset(parent->procinfo, 0, sizeof *(parent->procinfo));              log("stop: (%s) %s\n", parent->name, parent->stop->arg[0]);
391            /* Wait until the process is actually stopped before atempting              spawn(parent, parent->stop);
392             * to restart it */              memset(parent->procinfo, 0, sizeof *(parent->procinfo));
393            while(max_tries--) {              /* Wait until the process is actually stopped */
394              if(!is_process_running(parent))              while(max_tries--) {
395                  break;                if(!is_process_running(parent))
396              sleep(1);                    break;
397                  sleep(1);
398                }
399              }
400            } else if(is(action, "start")) {
401              if(! is_process_running(parent)) {
402                log("start: (%s) %s\n", parent->name, parent->start->arg[0]);
403                spawn(parent, parent->start);
404            }            }
405          }          }
406          if(! is_process_running(parent)) {          do_dependandt(parent, action);
           log("start: (%s) %s\n", parent->name, parent->start->arg[0]);  
           spawn(parent, parent->start);  
         }  
         do_restart_dependandt(parent);  
407        }        }
408      }      }
409    }    }

Legend:
Removed from v.1.25  
changed lines
  Added in v.1.26

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