43 |
/* Private Prototypes */ |
/* Private Prototypes */ |
44 |
static void wait_stop(Process_T); |
static void wait_stop(Process_T); |
45 |
static void wait_start(Process_T); |
static void wait_start(Process_T); |
46 |
static void do_stop(Process_T, int); |
static void do_stop(Process_T); |
47 |
static void do_start(Process_T, int); |
static void do_start(Process_T); |
48 |
static void do_depend(Process_T, char *, int); |
static void do_depend(Process_T, char *); |
49 |
|
|
50 |
|
|
51 |
/** |
/** |
53 |
* |
* |
54 |
* @author Jan-Henrik Haukeland, <hauk@tildeslash.com> |
* @author Jan-Henrik Haukeland, <hauk@tildeslash.com> |
55 |
* @author Rory Toma, <rory@digeo.com> |
* @author Rory Toma, <rory@digeo.com> |
56 |
|
* @author Martin Pala, <martin.pala@hq.iol.cz> |
57 |
* |
* |
58 |
* @version \$Id$ |
* @version \$Id$ |
59 |
* |
* |
66 |
/** |
/** |
67 |
* Start/stop all processes in process list |
* Start/stop all processes in process list |
68 |
* @param action A string describing the action to execute |
* @param action A string describing the action to execute |
|
* @param toggle_validate_flag passed on to the start/stop functions |
|
69 |
*/ |
*/ |
70 |
void control(char *action, int toggle_validate_flag) { |
void control(char *action) { |
71 |
|
|
72 |
Process_T p; |
Process_T p; |
73 |
|
|
79 |
if(exist_daemon()) { |
if(exist_daemon()) { |
80 |
d_check_process(p->name, action); |
d_check_process(p->name, action); |
81 |
} else { |
} else { |
82 |
check_process(p->name, action, toggle_validate_flag); |
check_process(p->name, action); |
83 |
} |
} |
84 |
} |
} |
85 |
|
|
92 |
* Start/stop all processes in a group |
* Start/stop all processes in a group |
93 |
* @param G group name |
* @param G group name |
94 |
* @param action A string describing the action to execute |
* @param action A string describing the action to execute |
|
* @param toggle_validate_flag passed on to the start/stop functions |
|
95 |
*/ |
*/ |
96 |
void control_group(char *G, char *action, int toggle_validate_flag) { |
void control_group(char *G, char *action) { |
97 |
|
|
98 |
Process_T p; |
Process_T p; |
99 |
|
|
107 |
if(exist_daemon()) { |
if(exist_daemon()) { |
108 |
d_check_process(p->name, action); |
d_check_process(p->name, action); |
109 |
} else { |
} else { |
110 |
check_process(p->name, action, toggle_validate_flag); |
check_process(p->name, action); |
111 |
} |
} |
112 |
} |
} |
113 |
} |
} |
189 |
* Check to see if we should try to start/stop process |
* Check to see if we should try to start/stop process |
190 |
* @param P A process name as stated in the config file |
* @param P A process name as stated in the config file |
191 |
* @param action A string describing the action to execute |
* @param action A string describing the action to execute |
|
* @param toggle_validate_flag passed on to the start/stop functions |
|
192 |
*/ |
*/ |
193 |
void check_process(char *P, char *action, int toggle_validate_flag) { |
void check_process(char *P, char *action) { |
194 |
|
|
195 |
Process_T p= NULL; |
Process_T p= NULL; |
196 |
|
|
215 |
return; |
return; |
216 |
} |
} |
217 |
|
|
218 |
do_depend(p, "stop", toggle_validate_flag); |
do_depend(p, "stop"); |
219 |
do_start(p, toggle_validate_flag); |
do_start(p); |
220 |
do_depend(p, "start", toggle_validate_flag); |
do_depend(p, "start"); |
221 |
|
|
222 |
} else if(is(action, "stop")) { |
} else if(is(action, "stop")) { |
223 |
|
|
227 |
return; |
return; |
228 |
} |
} |
229 |
|
|
230 |
do_depend(p, "stop", toggle_validate_flag); |
do_depend(p, "stop"); |
231 |
do_stop(p, toggle_validate_flag); |
do_stop(p); |
232 |
|
|
233 |
|
} else if(is(action, "restart")) { |
234 |
|
|
235 |
|
if(!p->start || !p->stop) { |
236 |
|
error("%s: Start or stop method not defined -- process %s\n", |
237 |
|
prog, P); |
238 |
|
return; |
239 |
|
} |
240 |
|
|
241 |
|
do_depend(p, "stop"); |
242 |
|
do_stop(p); |
243 |
|
do_start(p); |
244 |
|
do_depend(p, "start"); |
245 |
|
|
246 |
} |
} |
247 |
|
|
270 |
* This is a post- fix recursive function for starting every process |
* This is a post- fix recursive function for starting every process |
271 |
* that p depends on before starting p. |
* that p depends on before starting p. |
272 |
* @param p A Process_T object |
* @param p A Process_T object |
|
* @param toggle_validate_flag Turn on validate if defined |
|
273 |
*/ |
*/ |
274 |
static void do_start(Process_T p, int toggle_validate_flag) { |
static void do_start(Process_T p) { |
275 |
|
|
276 |
ASSERT(p); |
ASSERT(p); |
277 |
|
|
288 |
|
|
289 |
Process_T dp= get_process(d->dependant); |
Process_T dp= get_process(d->dependant); |
290 |
ASSERT(dp); |
ASSERT(dp); |
291 |
do_start(dp, toggle_validate_flag); |
do_start(dp); |
292 |
|
|
293 |
} |
} |
294 |
} |
} |
295 |
|
|
296 |
if(toggle_validate_flag) { |
LOCK(Run.mutex) |
297 |
LOCK(Run.mutex) |
p->do_validate= TRUE; |
298 |
p->do_validate= TRUE; |
END_LOCK; |
299 |
END_LOCK; |
|
300 |
if(Run.debug) |
if(Run.debug) |
301 |
log("Monitoring enabled -- process %s\n", p->name); |
log("Monitoring enabled -- process %s\n", p->name); |
|
} |
|
302 |
|
|
303 |
if(p->start && p->do_validate && (!is_process_running(p))) { |
if(p->start && (!is_process_running(p))) { |
304 |
log("start: (%s) %s\n", p->name, p->start->arg[0]); |
log("start: (%s) %s\n", p->name, p->start->arg[0]); |
305 |
spawn(p, p->start); |
spawn(p, p->start); |
306 |
wait_start(p); |
wait_start(p); |
312 |
/* |
/* |
313 |
* This function simply stops the process p. |
* This function simply stops the process p. |
314 |
* @param p A Process_T object |
* @param p A Process_T object |
|
* @param toggle_validate_flag Turn off validate if defined |
|
315 |
*/ |
*/ |
316 |
static void do_stop(Process_T p, int toggle_validate_flag) { |
static void do_stop(Process_T p) { |
317 |
|
|
318 |
ASSERT(p); |
ASSERT(p); |
319 |
|
|
322 |
|
|
323 |
p->depend_visited= TRUE; |
p->depend_visited= TRUE; |
324 |
|
|
325 |
if(p->stop && p->do_validate && is_process_running(p)) { |
if(p->stop && is_process_running(p)) { |
326 |
log("stop: (%s) %s\n", p->name, p->stop->arg[0]); |
log("stop: (%s) %s\n", p->name, p->stop->arg[0]); |
327 |
spawn(p, p->stop); |
spawn(p, p->stop); |
328 |
wait_stop(p); |
wait_stop(p); |
331 |
/* Reset the proc info object in case of a later restart */ |
/* Reset the proc info object in case of a later restart */ |
332 |
memset(p->procinfo, 0, sizeof *(p->procinfo)); |
memset(p->procinfo, 0, sizeof *(p->procinfo)); |
333 |
|
|
334 |
if(toggle_validate_flag) { |
LOCK(Run.mutex) |
335 |
LOCK(Run.mutex) |
p->do_validate= FALSE; |
336 |
p->do_validate= FALSE; |
END_LOCK; |
337 |
END_LOCK; |
|
338 |
if(Run.debug) |
if(Run.debug) |
339 |
log("Monitoring disabled -- process %s\n", p->name); |
log("Monitoring disabled -- process %s\n", p->name); |
|
} |
|
340 |
|
|
341 |
} |
} |
342 |
|
|
349 |
* the procceses that depends on p. |
* the procceses that depends on p. |
350 |
* @param p A Process_T object |
* @param p A Process_T object |
351 |
* @param action An action to do on the dependant processes |
* @param action An action to do on the dependant processes |
|
* @param toggle_validate_flag passed to the start/stop functions |
|
352 |
*/ |
*/ |
353 |
static void do_depend(Process_T p, char *action, int toggle_validate_flag) { |
static void do_depend(Process_T p, char *action) { |
354 |
|
|
355 |
Process_T parent; |
Process_T parent; |
356 |
|
|
369 |
if(d) { |
if(d) { |
370 |
|
|
371 |
if(is(action, "start")) |
if(is(action, "start")) |
372 |
do_start(parent, toggle_validate_flag); |
do_start(parent); |
373 |
|
|
374 |
do_depend(parent, action, toggle_validate_flag); |
do_depend(parent, action); |
375 |
|
|
376 |
if(is(action, "stop")) |
if(is(action, "stop")) |
377 |
do_stop(parent, toggle_validate_flag); |
do_stop(parent); |
378 |
|
|
379 |
} |
} |
380 |
} |
} |