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

Diff of /monit/control.c

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

revision 1.12 by rory, Thu Dec 5 01:36:27 2002 UTC revision 1.13 by rory, Fri Dec 6 19:40:49 2002 UTC
# Line 37  Line 37 
37    
38    
39  /* Private Prototypes */  /* Private Prototypes */
40  static void control_process(Process_T p, char *action);  static void control_process(Process_T p, char *action, int toggle_validate_flag);
41  static void atomic_control_process(Process_T p, char *action);  static void atomic_control_process(Process_T p, char *action);
42  static void control_dependant_process(Process_T p, char *action);  static void control_dependant_process(Process_T p, char *action, int toggle_validate_flag);
43  static void mark_dependants(Process_T p);  static void mark_dependants(Process_T p);
44    
45  /**  /**
# Line 111  void control_group(char *G, char *action Line 111  void control_group(char *G, char *action
111   * Pass on to methods in http/cervlet.c to start/stop processes   * Pass on to methods in http/cervlet.c to start/stop processes
112   * @param name A process name as stated in the config file   * @param name A process name as stated in the config file
113   * @param action A string describing the action to execute   * @param action A string describing the action to execute
  * @param toggle_validate_flag A flag telling us whether we should change do_validate  
114   */   */
115  void d_check_process(char *P, char *action) {  void d_check_process(char *P, char *action) {
116    
117    int s;    int s;
118    char req[2*STRLEN];    char req[2*STRLEN];
119    char *auth= get_basic_authentication_header();    char *auth= get_basic_authentication_header();
120      ssl_connection * ssl= NULL;
121    
122    s= create_socket(Run.bind_addr?Run.bind_addr:"localhost",    if ( Run.httpdssl ) {
123                     Run.httpdport, SOCK_STREAM);      
124        ssl = new_ssl_connection(Run.httpsslpem);
125        
126      }
127    
128      s= create_socket(Run.bind_addr?Run.bind_addr:"localhost",
129                       Run.httpdport, SOCK_STREAM);
130      
131    if(s<0) {    if(s<0) {
132      error("%s: Cannot connect to the monit daemon. "      error("%s: Cannot connect to the monit daemon. "
133            "Did you start it with http support?\n", prog);            "Did you start it with http support?\n", prog);
# Line 130  void d_check_process(char *P, char *acti Line 136  void d_check_process(char *P, char *acti
136    else {    else {
137      snprintf(req, sizeof(req),      snprintf(req, sizeof(req),
138               "GET /%s?action=%s HTTP/1.0\r\n%s\r\n", P, action, auth);               "GET /%s?action=%s HTTP/1.0\r\n%s\r\n", P, action, auth);
139      sock_send(s, req, sizeof(req), 0);      
140      close_socket(s);      if ( ssl != NULL ) {
141          
142          if (!embed_ssl_socket(ssl, s)) {
143            
144            fprintf(stdout, "Failed establish SSL communication to monit"
145                    " server\n");
146            
147            return;
148          }
149          
150          send_ssl_socket(ssl, req, sizeof(req));
151          
152          close_ssl_socket(ssl);
153          close_socket(s);
154          
155        } else {
156          
157          sock_send(s, req, sizeof(req), 0);
158          close_socket(s);
159          
160        }
161      free(auth);      free(auth);
162    }    }
163        
164      if ( Run.httpdssl ) {
165        
166        delete_ssl_socket(ssl);
167    
168      }
169  }  }
170    
171    
# Line 145  void d_check_process(char *P, char *acti Line 176  void d_check_process(char *P, char *acti
176   */   */
177  void check_process(char *P, char *action, int toggle_validate_flag) {  void check_process(char *P, char *action, int toggle_validate_flag) {
178    
   int pid;  
179    Process_T p= NULL;    Process_T p= NULL;
180    
181    ASSERT(P);    ASSERT(P);
# Line 173  void check_process(char *P, char *action Line 203  void check_process(char *P, char *action
203    
204    }    }
205                
   if( p->visited == TRUE ) {  
     return;  
   }  
206    
207      /* If parent process isn't running, then return, as validate will
208       * pick up the parent process and start the dependants.
209       */
210    if(is(action, "start")) {    if(is(action, "start")) {
   
     if ( (pid= is_process_running(p)) ) {  
       error("%s: '%s' is already running with pid%d\n", prog, P, pid);  
       return;  
     }  
     if(! p->start) {  
       error("start: '%s' the start program is not defined\n", p->name);  
       return;  
     }  
   
     if( p->parent != NULL ) {  
       check_process(p->parent, action, toggle_validate_flag);  
     }  
   }  
   else if(is(action, "stop")) {  
211            
212      if(! is_process_running(p)) {      if( p->parent != NULL ) {
213        error("%s: '%s' is not running\n", prog, P);        if( !is_process_running(get_process(p->parent)) ) {
214        return;          log("Not starting process: %s, parent process: %s is not running\n",
215      }              p->name, p->parent);
216      if(! p->stop) {          return;
217        error("stop: '%s' the stop program is not defined\n", p->name);        }
       return;  
218      }      }
219    }    }
220    
221    control_process(p, action);    control_process(p, action, toggle_validate_flag);
   
   p->visited= TRUE;  
222    
223  }  }
224    
# Line 247  void setup_dependants() { Line 259  void setup_dependants() {
259   * @param action A string describing the action to execute   * @param action A string describing the action to execute
260   * @param daemon Flag indicating if the monit daemon should execute the action   * @param daemon Flag indicating if the monit daemon should execute the action
261   */   */
262  void control_process(Process_T p, char *action) {  void control_process(Process_T p, char *action, int toggle_validate_flag) {
263    
264    ASSERT(action);    ASSERT(action);
265    
266    /* Stop dependant processes */    /* Stop dependant processes */
267    control_dependant_process(p, "stop");    control_dependant_process(p, "stop", toggle_validate_flag);
268        
269    /* Start/stop the process we asked for */    /* Start/stop the process we asked for */
270    atomic_control_process(p, action);    atomic_control_process(p, action);
271    
272    /* Restart dependant processes if needed */    /* Restart dependant processes if needed */
273    if(is(action, "start")) {    if(is(action, "start")) {
274      control_dependant_process(p, action);      control_dependant_process(p, action, toggle_validate_flag);
275    }    }
276  }  }
277    
# Line 273  static void atomic_control_process(Proce Line 285  static void atomic_control_process(Proce
285    
286    ASSERT(action);    ASSERT(action);
287    
288      if( p->visited == TRUE ) {
289        return;
290      }
291    
292    if(is(action, "start")) {    if(is(action, "start")) {
293        ASSERT(p->start);
294      if(! is_process_running(p)) {      if(! is_process_running(p)) {
295        log("%s: (%s) %s\n", action, p->name, p->start->arg[0]);        log("%s: (%s) %s\n", action, p->name, p->start->arg[0]);
296        spawn(p, p->start);        spawn(p, p->start);
297          p->visited= TRUE;
298                
299      }      }
300    }    }
301    else if(is(action, "stop")) {    else if(is(action, "stop")) {
302        ASSERT(p->stop);
303      if(is_process_running(p)) {      if(is_process_running(p)) {
304        log("%s: (%s) %s\n", action, p->name, p->stop->arg[0]);        log("%s: (%s) %s\n", action, p->name, p->stop->arg[0]);
305        spawn(p, p->stop);        spawn(p, p->stop);
306          p->visited= TRUE;
307      }      }
308    }    }
309        
# Line 295  static void atomic_control_process(Proce Line 315  static void atomic_control_process(Proce
315   * @param p A Process_T object @param action A start/stop action   * @param p A Process_T object @param action A start/stop action
316   * @param daemon Flag indicating if the monit daemon should execute the action   * @param daemon Flag indicating if the monit daemon should execute the action
317   */   */
318  static void control_dependant_process(Process_T p, char *action) {  static void control_dependant_process(Process_T p, char *action, int toggle_validate_flag) {
319    
   Process_T dp;  
320    Dependant_T d;    Dependant_T d;
321    
322    ASSERT(action);    ASSERT(action);
# Line 306  static void control_dependant_process(Pr Line 325  static void control_dependant_process(Pr
325      if(d->dependant == NULL) {      if(d->dependant == NULL) {
326        break;        break;
327      }      }
328      dp= get_process(d->dependant);      check_process(d->dependant, action, toggle_validate_flag);
     control_process(dp, action);  
329    }    }
330        
331  }  }
# Line 326  void mark_dependants(Process_T p) { Line 344  void mark_dependants(Process_T p) {
344      if( d->dependant == NULL ) {      if( d->dependant == NULL ) {
345        break;        break;
346    
347      }      } else {
348            
349      dp= get_process(d->dependant);        dp= get_process(d->dependant);
350      dp->parent= p->name;        dp->parent= p->name;
351    
352        }
353    
354    }    }
355    
356  }  }
357    

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

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