328 |
|
|
329 |
kill -1 1 |
kill -1 1 |
330 |
|
|
331 |
B<Things you need to know if you choose to start monit from |
If monit is used to monitor services that are also started at |
332 |
init:> If monit is used to monitor services that are also started |
boot time (e.g. services started via SYSV init rc scripts or via |
333 |
at boot time (e.g. services started via SYSV init rc scripts or |
inittab) then in some situations a race condition can occur. That |
334 |
via inittab) then in some situations a special race condition can |
is; if a service is slow to start, monit can assume that the |
335 |
occur. That is; if a service is slow to start, monit can assume |
service is not running and possibly try to start it and raise an |
336 |
that the service is not running and possibly try to start it and |
alert, while, in fact the service is already about to start or |
337 |
raise an alert, while, in fact the service is already about to |
already in its startup sequence. Please see the FAQ for solutions |
338 |
start or already in its startup sequence. If you experience this |
to this problem. |
|
problem, here are a couple of strategies you can use to prevent |
|
|
this type of race condition: |
|
|
|
|
|
|
|
|
=over 4 |
|
|
|
|
|
=item start critical services directly from monit: |
|
|
|
|
|
This is the recommended solution - let monit takeover the |
|
|
responsibility for starting services. To use this strategy you |
|
|
must turn off the systems automatic start and stop for all |
|
|
services handled by monit. |
|
|
|
|
|
On RedHat, you can for example use: |
|
|
|
|
|
chkconfig myprocess off |
|
|
|
|
|
on Debian: |
|
|
|
|
|
update-rc.d -f myprocess remove |
|
|
|
|
|
a general example: |
|
|
|
|
|
mv /etc/rc2.d/S99myprocess /etc/rc2.d/s99myprocess |
|
|
|
|
|
If monit is started from a rc script, then to stop the service at |
|
|
systems shutdown, you should add the following line to monit's rc |
|
|
script: |
|
|
|
|
|
/usr/local/bin/monit -c /etc/monitrc stop myprocess |
|
|
|
|
|
or if monit handles more than one service, simply stop all |
|
|
services by using: |
|
|
|
|
|
/usr/local/bin/monit -c /etc/monitrc stop all |
|
|
|
|
|
If monit instead is started from init then, add a second line to |
|
|
inittab to stop the service: |
|
|
|
|
|
mo:2345:respawn:/usr/local/bin/monit -Ic /etc/monitrc |
|
|
m0:06:wait:/usr/local/bin/monit -Ic /etc/monitrc stop myprocess |
|
|
|
|
|
or to stop all services handled by monit: |
|
|
|
|
|
mo:2345:respawn:/usr/local/bin/monit -Ic /etc/monitrc |
|
|
m0:06:wait:/usr/local/bin/monit -Ic /etc/monitrc stop all |
|
|
|
|
|
Services handled by monit I<must> have start and stop methods |
|
|
defined so monit can start and stop a service. For instance: |
|
|
|
|
|
check process myprocess with pidfile /var/run/myprocess.pid |
|
|
start program = "/etc/init.d/myprocess start" |
|
|
stop program = "/etc/init.d/myprocess stop" |
|
|
alert foo@bar.baz |
|
|
|
|
|
=item make init wait for a service to start: |
|
|
|
|
|
This solution will make the init process wait for the service to |
|
|
start before it will continue to start other services. If you are |
|
|
running monit from init, you must enter monit's line at the end |
|
|
of /etc/inittab (A short example): |
|
|
|
|
|
si::sysinit:/etc/init.d/rcS |
|
|
... |
|
|
l2:2:wait:/etc/init.d/rc 2 |
|
|
... |
|
|
mo:2345:respawn:/usr/local/bin/monit -Ic /etc/monitrc |
|
|
|
|
|
The rc script for the monitored service must be I<modified> so, |
|
|
that it will not return unless the service was started or start |
|
|
of the service timed out. Creative use of sleep(1) may be |
|
|
sufficient. |
|
|
|
|
|
As in the above example, services handled by monit must have |
|
|
start and stop methods defined, such as for example: |
|
|
|
|
|
check process myprocess with pidfile /var/run/myprocess.pid |
|
|
start program = "/etc/init.d/myprocess start" |
|
|
stop program = "/etc/init.d/myprocess stop" |
|
|
alert foo@bar.baz |
|
|
|
|
|
=item enable the service monitoring manually from monit: |
|
|
|
|
|
check file myprocess.pid with path /var/run/myprocess.pid |
|
|
if timestamp > 5 minutes then |
|
|
exec "/bin/bash -c ' |
|
|
/usr/bin/monit -c /etc/monitrc monitor myprocess; |
|
|
/usr/bin/monit -c /etc/monitrc unmonitor myprocess.pid |
|
|
'" |
|
|
check process myprocess with pidfile /var/run/myprocess.pid |
|
|
start program = "/etc/init.d/myprocess start" |
|
|
stop program = "/etc/init.d/myprocess stop" |
|
|
alert foo@bar.baz |
|
|
mode manual |
|
|
|
|
|
This will cause monit to wait for 5 minutes before it will enable |
|
|
monitoring of the service myprocess. |
|
|
|
|
|
=back |
|
|
|
|
339 |
|
|
340 |
|
|
341 |
=head1 GROUP SUPPORT |
=head1 GROUP SUPPORT |
633 |
if 2 restarts within 3 cycles then timeout |
if 2 restarts within 3 cycles then timeout |
634 |
|
|
635 |
To have monit check the service again after a timeout, run 'monit |
To have monit check the service again after a timeout, run 'monit |
636 |
start service' from the command line. This will remove the |
monitor service' from the command line. This will remove the |
637 |
timeout lock in the daemon and make the daemon start and check |
timeout lock in the daemon and make the daemon start and check |
638 |
the service again. |
the service again. |
639 |
|
|
1612 |
username and/or password are logged with their ip-address. |
username and/or password are logged with their ip-address. |
1613 |
|
|
1614 |
|
|
1615 |
=head1 DEPENDENCY TREE |
=head1 DEPENDENCIES |
1616 |
|
|
1617 |
If specified in the control file, monit can do dependency |
If specified in the control file, monit can do dependency |
1618 |
checking before start, stop, monitoring or unmonitoring of |
checking before start, stop, monitoring or unmonitoring of |
1675 |
A dependency tree is a general construct and can be used between |
A dependency tree is a general construct and can be used between |
1676 |
all types of service entries and span many levels and propagate |
all types of service entries and span many levels and propagate |
1677 |
any supported action (except the exec action which will not |
any supported action (except the exec action which will not |
1678 |
propagate upward in a dependency tree for obvious reasons). Here |
propagate upward in a dependency tree for obvious reasons). |
|
is another example, based on a different perspective, but with a |
|
|
depend tree as the baseline: |
|
1679 |
|
|
1680 |
|
Here is another different example. Consider the following common |
1681 |
Consider the following common server setup: |
server setup: |
1682 |
|
|
1683 |
WEB-SERVER -> APPLICATION-SERVER -> DATABASE -> FILESYSTEM |
WEB-SERVER -> APPLICATION-SERVER -> DATABASE -> FILESYSTEM |
1684 |
(a) (b) (c) (d) |
(a) (b) (c) (d) |
1739 |
|
|
1740 |
|
|
1741 |
|
|
|
|
|
1742 |
=head1 THE RUN CONTROL FILE |
=head1 THE RUN CONTROL FILE |
1743 |
|
|
1744 |
The preferred way to set up monit is to write a I<.monitrc> file |
The preferred way to set up monit is to write a I<.monitrc> file |