73 |
setup_dependants(); |
setup_dependants(); |
74 |
|
|
75 |
for(p= processlist; p; p= p->next) { |
for(p= processlist; p; p= p->next) { |
76 |
if( exist_daemon() ) { |
if(exist_daemon()) { |
77 |
d_check_process(p->name, action); |
d_check_process(p->name, action); |
78 |
} else { |
} else { |
79 |
check_process(p->name, action, toggle_validate_flag); |
check_process(p->name, action, toggle_validate_flag); |
99 |
|
|
100 |
for(p= processlist; p; p= p->next) { |
for(p= processlist; p; p= p->next) { |
101 |
if(is(p->group, G)) { |
if(is(p->group, G)) { |
102 |
if( exist_daemon() ) { |
if(exist_daemon()) { |
103 |
d_check_process(p->name, action); |
d_check_process(p->name, action); |
104 |
} else { |
} else { |
105 |
check_process(p->name, action, toggle_validate_flag); |
check_process(p->name, action, toggle_validate_flag); |
121 |
int s; |
int s; |
122 |
char req[2*STRLEN]; |
char req[2*STRLEN]; |
123 |
char *auth= get_basic_authentication_header(); |
char *auth= get_basic_authentication_header(); |
124 |
ssl_connection * ssl= NULL; |
ssl_connection *ssl= NULL; |
125 |
|
|
126 |
ASSERT(P); |
ASSERT(P); |
127 |
ASSERT(action); |
ASSERT(action); |
128 |
|
|
129 |
if ( Run.httpdssl ) { |
if(Run.httpdssl) { |
130 |
|
|
131 |
ssl = new_ssl_connection(Run.httpsslpem); |
ssl= new_ssl_connection(Run.httpsslpem); |
132 |
|
|
133 |
} |
} |
134 |
|
|
135 |
s= create_socket(Run.bind_addr?Run.bind_addr:"localhost", |
s= create_socket(Run.bind_addr?Run.bind_addr:"localhost", |
136 |
Run.httpdport, SOCK_STREAM); |
Run.httpdport, SOCK_STREAM); |
137 |
|
|
138 |
if(s<0) { |
if(s < 0) { |
139 |
|
|
140 |
error("%s: Cannot connect to the monit daemon. " |
error("%s: Cannot connect to the monit daemon. " |
141 |
"Did you start it with http support?\n", prog); |
"Did you start it with http support?\n", prog); |
142 |
return; |
goto error; |
143 |
} |
|
144 |
else { |
} else { |
145 |
snprintf(req, sizeof(req), |
snprintf(req, sizeof(req), |
146 |
"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); |
147 |
|
|
148 |
if ( ssl != NULL ) { |
if(ssl) { |
149 |
|
|
150 |
if (!embed_ssl_socket(ssl, s)) { |
if(!embed_ssl_socket(ssl, s)) { |
151 |
|
|
152 |
fprintf(stdout, "Failed establish SSL communication to monit" |
fprintf(stdout, "Failed establish SSL communication to monit" |
153 |
" server\n"); |
" server\n"); |
154 |
|
goto error; |
|
return; |
|
155 |
} |
} |
156 |
|
|
157 |
send_ssl_socket(ssl, req, sizeof(req)); |
send_ssl_socket(ssl, req, sizeof(req)); |
165 |
close_socket(s); |
close_socket(s); |
166 |
|
|
167 |
} |
} |
|
free(auth); |
|
168 |
} |
} |
169 |
|
|
170 |
if ( Run.httpdssl ) { |
if(Run.httpdssl) { |
171 |
|
|
172 |
delete_ssl_socket(ssl); |
delete_ssl_socket(ssl); |
173 |
|
|
174 |
} |
} |
175 |
|
|
176 |
|
error: |
177 |
|
free(auth); |
178 |
|
|
179 |
} |
} |
180 |
|
|
181 |
|
|
197 |
return; |
return; |
198 |
} |
} |
199 |
|
|
200 |
if( toggle_validate_flag ) { |
if(toggle_validate_flag) { |
201 |
|
|
202 |
if( is(action, "start")) { |
if( is(action, "start")) { |
203 |
LOCK(Run.mutex) |
LOCK(Run.mutex) |
233 |
return; |
return; |
234 |
} |
} |
235 |
|
|
236 |
if( p->parent != NULL ) { |
if(p->parent) { |
237 |
if( !is_process_running(get_process(p->parent)) ) { |
if( !is_process_running(get_process(p->parent)) ) { |
238 |
log("Skipping '%s', waiting for '%s' to start\n", |
log("Skipping '%s', waiting for '%s' to start\n", |
239 |
p->name, p->parent); |
p->name, p->parent); |
265 |
|
|
266 |
Process_T p; |
Process_T p; |
267 |
|
|
268 |
for (p= processlist; p; p= p->next) { |
for(p= processlist; p; p= p->next) { |
269 |
|
|
270 |
p->visited= FALSE; |
p->visited= FALSE; |
271 |
p->parent= NULL; |
p->parent= NULL; |
272 |
|
|
273 |
} |
} |
274 |
|
|
275 |
for (p= processlist; p; p= p->next) { |
for(p= processlist; p; p= p->next) { |
276 |
|
|
277 |
if( p->dependantlist != NULL ) { |
if(p->dependantlist != NULL) { |
278 |
|
|
279 |
mark_dependants(p); |
mark_dependants(p); |
280 |
|
|
319 |
|
|
320 |
ASSERT(action); |
ASSERT(action); |
321 |
|
|
322 |
if( p->visited == TRUE ) { |
if(p->visited) { |
323 |
return; |
return; |
324 |
} |
} |
325 |
|
|
329 |
log("%s: (%s) %s\n", action, p->name, p->start->arg[0]); |
log("%s: (%s) %s\n", action, p->name, p->start->arg[0]); |
330 |
spawn(p, p->start); |
spawn(p, p->start); |
331 |
p->visited= TRUE; |
p->visited= TRUE; |
332 |
if( !is_process_running(p) ) { |
if(!is_process_running(p)) { |
333 |
sleep(Run.polltime); |
sleep(Run.polltime); |
334 |
} |
} |
335 |
|
|
353 |
* @param p A Process_T object @param action A start/stop action |
* @param p A Process_T object @param action A start/stop action |
354 |
* @param daemon Flag indicating if the monit daemon should execute the action |
* @param daemon Flag indicating if the monit daemon should execute the action |
355 |
*/ |
*/ |
356 |
static void control_dependant_process(Process_T p, char *action, int toggle_validate_flag) { |
static void control_dependant_process(Process_T p, char *action, |
357 |
|
int toggle_validate_flag) { |
358 |
|
|
359 |
Dependant_T d; |
Dependant_T d; |
360 |
|
|
372 |
/** |
/** |
373 |
* Mark the visited flag on dependant so we don't visit them more than once |
* Mark the visited flag on dependant so we don't visit them more than once |
374 |
*/ |
*/ |
|
|
|
375 |
void mark_dependants(Process_T p) { |
void mark_dependants(Process_T p) { |
376 |
|
|
377 |
Process_T dp; |
Process_T dp; |
378 |
Dependant_T d; |
Dependant_T d; |
379 |
|
|
380 |
for (d= p->dependantlist; d; d= d->next ) { |
for(d= p->dependantlist; d; d= d->next ) { |
|
|
|
|
if( (dp= get_process(d->dependant)) != NULL ) { |
|
381 |
|
|
382 |
|
if((dp= get_process(d->dependant)) != NULL) { |
383 |
|
|
384 |
dp->parent= p->name; |
dp->parent= p->name; |
385 |
|
|
386 |
} else { |
} else { |
387 |
|
|
388 |
break; |
break; |
389 |
|
|
390 |
} |
} |
391 |
|
|
392 |
} |
} |
393 |
|
|
394 |
} |
} |
395 |
|
|
396 |
|
|