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

Diff of /monit/start.c

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

revision 1.10 by hauk, Fri Sep 6 18:13:37 2002 UTC revision 1.11 by rory, Wed Sep 25 22:43:38 2002 UTC
# Line 124  void start_process(Process_T p) { Line 124  void start_process(Process_T p) {
124   */   */
125  void dstart_process(char *P) {  void dstart_process(char *P) {
126    
127    int pid;    Dependant_T d;
128        Process_T p;
129      int pid, s;
130    
131    if ( ! exist_process(P) ) {    if ( ! exist_process(P) ) {
132            
133      error("%s: Cannot start program '%s' -- not found in %s\n",      error("%s: Cannot start program '%s' -- not found in %s\n",
# Line 134  void dstart_process(char *P) { Line 136  void dstart_process(char *P) {
136      return;      return;
137            
138    }    }
139      
140    if ( (pid= is_process_running(get_process(P))) ) {    p= get_process(P);
141    
142      if ( (pid= is_process_running(p))) {
143            
144      error("%s: '%s' is already running with pid=%d\n", prog, P, pid);      error("%s: '%s' is already running with pid=%d\n", prog, P, pid);
145            
146      return;      return;
147            
148    }    }
149      
150    if ( exist_daemon() ) {    if ( exist_daemon() ) {
151            
152      /* If a monit daemon exist we request that the daemon start the      /* If a monit daemon exist we request that the daemon start the
153         program in case the daemon timed out the program. This way any         program in case the daemon timed out the program. This way any
154         process timeout lock in the daemon is removed */         process timeout lock in the daemon is removed */
155    
156        char req[2*STRLEN];
157        char *auth= get_basic_authentication_header();    
158            
159      int s= create_socket(Run.bind_addr?Run.bind_addr:"localhost",      /* stop dependant processes */
160                           Run.httpdport, SOCK_STREAM);      for(d= p->dependantlist; d; d= p->dependantlist->next) {
161              if(d->dependant == NULL) {
162      if (s<0) {          break;
163                }
164          s= create_socket(Run.bind_addr?Run.bind_addr:"localhost",
165                           Run.httpdport, SOCK_STREAM);
166          if(s<0) {
167            error("%s: Cannot connect to the monit daemon. "
168                  "Did you start it with http support?\n", prog);
169            return;
170          } else {
171            snprintf(req, 2*STRLEN,
172                     "GET /%s?action=stop HTTP/1.0\r\n%s\r\n", d->dependant, auth);
173            sock_send(s, req, sizeof(req), 0);
174            close_socket(s);
175            if(d->next == NULL) {
176              break;
177            }
178          }
179        }
180    
181        /* Now start the process we asked for */
182        s= create_socket(Run.bind_addr?Run.bind_addr:"localhost",
183                         Run.httpdport, SOCK_STREAM);
184        if(s<0) {
185        error("%s: Cannot connect to the monit daemon. "        error("%s: Cannot connect to the monit daemon. "
186              "Did you start it with http support?\n", prog);              "Did you start it with http support?\n", prog);
         
187        return;        return;
         
188      } else {      } else {
   
       char req[2*STRLEN];  
       char *auth= get_basic_authentication_header();  
         
189        snprintf(req, 2*STRLEN,        snprintf(req, 2*STRLEN,
190                 "GET /%s?action=start HTTP/1.0\r\n%s\r\n", P, auth);                 "GET /%s?action=start HTTP/1.0\r\n%s\r\n", P, auth);
         
191        sock_send(s, req, sizeof(req), 0);        sock_send(s, req, sizeof(req), 0);
192        close_socket(s);        close_socket(s);
193        free(auth);        free(auth);
194              }
195        /* Set flags on dependant processes so they restart */
196        for(d= p->dependantlist; d; d= p->dependantlist->next) {
197          if(d->dependant == NULL) {
198            break;
199          }
200          start_process(get_process(d->dependant));
201          if(d->next == NULL) {
202            break;
203          }
204      }      }
205    } else {    } else {
206            
207      /* No monit daemon exist, just start the program */      /* No monit daemon exist, just start the program */
208      start_process(get_process(P));      /* stop dependant processes */
209            for(d= p->dependantlist; d; d= p->dependantlist->next) {
210          if(d->dependant == NULL) {
211            break;
212          }
213          stop_process(get_process(d->dependant));
214          if(d->next == NULL) {
215            break;
216          }
217        }
218        start_process(p);
219    
220        /* Set flags on dependant processes so they restart */
221        for(d= p->dependantlist; d; d= p->dependantlist->next) {
222          if(d->dependant == NULL) {
223            break;
224          }
225          start_process(get_process(d->dependant));
226          if(d->next == NULL) {
227            break;
228          }
229        }
230    }    }
     
231  }  }

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

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