328 |
|
|
329 |
kill -1 1 |
kill -1 1 |
330 |
|
|
331 |
|
In the case, that you are using SYSV init script for starting the |
332 |
|
monitored services and monit (either from init or rc its own rc |
333 |
|
script), in the special case of slow starting monitored service |
334 |
|
you can observe the race condition between particular service's |
335 |
|
startup and its monitoring. In such case monit can produce false |
336 |
|
alarms. Possible solutions: |
337 |
|
|
338 |
|
=over 4 |
339 |
|
|
340 |
|
=item start critical services from monit directly: |
341 |
|
|
342 |
|
This is the recommended solution - monit will takeover the |
343 |
|
responsibility for service's startup. To use it you need to |
344 |
|
replace the service's start and stop in appropriate runlevels. |
345 |
|
You can use for example on RedHat: |
346 |
|
|
347 |
|
chkconfig myprocess off |
348 |
|
|
349 |
|
on Debian: |
350 |
|
|
351 |
|
update-rc.d -f myprocess remove |
352 |
|
|
353 |
|
general example: |
354 |
|
|
355 |
|
mv /etc/rc2.d/S99myprocess /etc/rc2.d/s99myprocess |
356 |
|
|
357 |
|
To stop the service on system shutdown, you need either to add |
358 |
|
for example following line to monit's rc script: |
359 |
|
|
360 |
|
/usr/local/bin/monit -c /etc/monitrc stop myprocess |
361 |
|
|
362 |
|
or to stop all services: |
363 |
|
|
364 |
|
/usr/local/bin/monit -c /etc/monitrc stop all |
365 |
|
|
366 |
|
If you are running monit from init then you can add the second |
367 |
|
line of following example to stop the service: |
368 |
|
|
369 |
|
mo:2345:respawn:/usr/local/bin/monit -Ic /etc/monitrc |
370 |
|
m0:06:wait:/usr/local/bin/monit -Ic /etc/monitrc stop myprocess |
371 |
|
|
372 |
|
or to stop all services: |
373 |
|
|
374 |
|
mo:2345:respawn:/usr/local/bin/monit -Ic /etc/monitrc |
375 |
|
m0:06:wait:/usr/local/bin/monit -Ic /etc/monitrc stop all |
376 |
|
|
377 |
|
The monitored service must have start and stop methods defined, |
378 |
|
such as for example: |
379 |
|
|
380 |
|
check process myprocess with pidfile /var/run/myprocess.pid |
381 |
|
start program = "/etc/init.d/myprocess start" |
382 |
|
stop program = "/etc/init.d/myprocess stop" |
383 |
|
alert foo@bar.baz |
384 |
|
|
385 |
|
=item wait for service to start |
386 |
|
|
387 |
|
This solution will cause that init process will wait for the service |
388 |
|
to start before it will continue to start other services. If you are |
389 |
|
running monit from init, you must define monit's line as last in |
390 |
|
/etc/inittab (short example): |
391 |
|
|
392 |
|
si::sysinit:/etc/init.d/rcS |
393 |
|
... |
394 |
|
l2:2:wait:/etc/init.d/rc 2 |
395 |
|
... |
396 |
|
mo:2345:respawn:/usr/local/bin/monit -Ic /etc/monitrc |
397 |
|
|
398 |
|
The rc script of the monitored service must be modified so, that it |
399 |
|
will not return unless the service will be online or the startup |
400 |
|
timed out. As dumb method sleep is sufficient. |
401 |
|
|
402 |
|
The monitored service must have start and stop methods defined, |
403 |
|
such as for example: |
404 |
|
|
405 |
|
check process myprocess with pidfile /var/run/myprocess.pid |
406 |
|
start program = "/etc/init.d/myprocess start" |
407 |
|
stop program = "/etc/init.d/myprocess stop" |
408 |
|
alert foo@bar.baz |
409 |
|
|
410 |
|
=item enable the service monitoring manualy |
411 |
|
|
412 |
|
check file myprocess.pid with path /var/run/myprocess.pid |
413 |
|
if timestamp > 5 minutes then |
414 |
|
exec "/bin/bash -c ' |
415 |
|
/usr/bin/monit -c /etc/monitrc monitor myprocess; |
416 |
|
/usr/bin/monit -c /etc/monitrc unmonitor myprocess.pid |
417 |
|
'" |
418 |
|
check process myprocess with pidfile /var/run/myprocess.pid |
419 |
|
start program = "/etc/init.d/myprocess start" |
420 |
|
stop program = "/etc/init.d/myprocess stop" |
421 |
|
alert foo@bar.baz |
422 |
|
mode manual |
423 |
|
|
424 |
|
This will cause to wait for 5 minutes before it will enable |
425 |
|
monitoring of the service myprocess. |
426 |
|
|
427 |
|
=back |
428 |
|
|
429 |
|
|
430 |
|
|
431 |
=head1 GROUP SUPPORT |
=head1 GROUP SUPPORT |