75 |
|
|
76 |
</UL> |
</UL> |
77 |
|
|
78 |
<LI><A HREF="#dependency tree">DEPENDENCY TREE</A></LI> |
<LI><A HREF="#dependencies">DEPENDENCIES</A></LI> |
79 |
<LI><A HREF="#the run control file">THE RUN CONTROL FILE</A></LI> |
<LI><A HREF="#the run control file">THE RUN CONTROL FILE</A></LI> |
80 |
<UL> |
<UL> |
81 |
|
|
365 |
For systems without telinit:</PRE> |
For systems without telinit:</PRE> |
366 |
<PRE> |
<PRE> |
367 |
kill -1 1</PRE> |
kill -1 1</PRE> |
368 |
<P><STRONG>Things you need to know if you choose to start monit from |
<P>If monit is used to monitor services that are also started at |
369 |
init:</STRONG> If monit is used to monitor services that are also started |
boot time (e.g. services started via SYSV init rc scripts or via |
370 |
at boot time (e.g. services started via SYSV init rc scripts or |
inittab) then in some situations a race condition can occur. That |
371 |
via inittab) then in some situations a special race condition can |
is; if a service is slow to start, monit can assume that the |
372 |
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 |
373 |
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 |
374 |
raise an alert, while, in fact the service is already about to |
already in its startup sequence. Please see the FAQ for solutions |
375 |
start or already in its startup sequence. If you experience this |
to this problem.</P> |
|
problem, here are a couple of strategies you can use to prevent |
|
|
this type of race condition:</P> |
|
|
<DL> |
|
|
<DT><STRONG><A NAME="item_start_critical_services_directly_from_monit%3A">start critical services directly from monit:</A></STRONG><BR> |
|
|
<DD> |
|
|
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. |
|
|
<P>On RedHat, you can for example use:</P> |
|
|
<PRE> |
|
|
chkconfig myprocess off</PRE> |
|
|
<P>on Debian:</P> |
|
|
<PRE> |
|
|
update-rc.d -f myprocess remove</PRE> |
|
|
<P>a general example:</P> |
|
|
<PRE> |
|
|
mv /etc/rc2.d/S99myprocess /etc/rc2.d/s99myprocess</PRE> |
|
|
<P>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:</P> |
|
|
<PRE> |
|
|
/usr/local/bin/monit -c /etc/monitrc stop myprocess</PRE> |
|
|
<P>or if monit handles more than one service, simply stop all |
|
|
services by using:</P> |
|
|
<PRE> |
|
|
/usr/local/bin/monit -c /etc/monitrc stop all</PRE> |
|
|
<P>If monit instead is started from init then, add a second line to |
|
|
inittab to stop the service:</P> |
|
|
<PRE> |
|
|
mo:2345:respawn:/usr/local/bin/monit -Ic /etc/monitrc |
|
|
m0:06:wait:/usr/local/bin/monit -Ic /etc/monitrc stop myprocess</PRE> |
|
|
<P>or to stop all services handled by monit:</P> |
|
|
<PRE> |
|
|
mo:2345:respawn:/usr/local/bin/monit -Ic /etc/monitrc |
|
|
m0:06:wait:/usr/local/bin/monit -Ic /etc/monitrc stop all</PRE> |
|
|
<P>Services handled by monit <EM>must</EM> have start and stop methods |
|
|
defined so monit can start and stop a service. For instance:</P> |
|
|
<PRE> |
|
|
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</PRE> |
|
|
<P></P> |
|
|
<DT><STRONG><A NAME="item_make_init_wait_for_a_service_to_start%3A">make init wait for a service to start:</A></STRONG><BR> |
|
|
<DD> |
|
|
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): |
|
|
<PRE> |
|
|
si::sysinit:/etc/init.d/rcS |
|
|
... |
|
|
l2:2:wait:/etc/init.d/rc 2 |
|
|
... |
|
|
mo:2345:respawn:/usr/local/bin/monit -Ic /etc/monitrc</PRE> |
|
|
<P>The rc script for the monitored service must be <EM>modified</EM> so, |
|
|
that it will not return unless the service was started or start |
|
|
of the service timed out. Creative use of <CODE>sleep(1)</CODE> may be |
|
|
sufficient.</P> |
|
|
<P>As in the above example, services handled by monit must have |
|
|
start and stop methods defined, such as for example:</P> |
|
|
<PRE> |
|
|
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</PRE> |
|
|
<P></P> |
|
|
<DT><STRONG><A NAME="item_enable_the_service_monitoring_manually_from_monit%">enable the service monitoring manually from monit:</A></STRONG><BR> |
|
|
<DD> |
|
|
<PRE> |
|
|
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</PRE> |
|
|
<P>This will cause monit to wait for 5 minutes before it will enable |
|
|
monitoring of the service myprocess.</P> |
|
|
</DL> |
|
376 |
<P> |
<P> |
377 |
<HR> |
<HR> |
378 |
<H1><A NAME="group support">GROUP SUPPORT</A></H1> |
<H1><A NAME="group support">GROUP SUPPORT</A></H1> |
615 |
<PRE> |
<PRE> |
616 |
if 2 restarts within 3 cycles then timeout</PRE> |
if 2 restarts within 3 cycles then timeout</PRE> |
617 |
<P>To have monit check the service again after a timeout, run 'monit |
<P>To have monit check the service again after a timeout, run 'monit |
618 |
start service' from the command line. This will remove the |
monitor service' from the command line. This will remove the |
619 |
timeout lock in the daemon and make the daemon start and check |
timeout lock in the daemon and make the daemon start and check |
620 |
the service again.</P> |
the service again.</P> |
621 |
<P> |
<P> |
829 |
if timestamp < 1 hour then alert</PRE> |
if timestamp < 1 hour then alert</PRE> |
830 |
<P>The following example is a hack for restarting a process after a |
<P>The following example is a hack for restarting a process after a |
831 |
certain time. Sometimes this is a necessary workaround for some |
certain time. Sometimes this is a necessary workaround for some |
832 |
third-party applications, until the vendor fix a problem (we |
third-party applications, until the vendor fix a problem:</P> |
|
didn't mention zeus did we?):</P> |
|
833 |
<PRE> |
<PRE> |
834 |
check file zerver.pid path /var/run/zerver.pid |
check file server.pid path /var/run/server.pid |
835 |
if timestamp > 7 days |
if timestamp > 7 days |
836 |
then exec "/usr/local/zerver/restart-zerver"</PRE> |
then exec "/usr/local/server/restart-server"</PRE> |
837 |
<P> |
<P> |
838 |
<H2><A NAME="file size testing">FILE SIZE TESTING</A></H2> |
<H2><A NAME="file size testing">FILE SIZE TESTING</A></H2> |
839 |
<P>Monit can monitor files for size changes and act on changes. This |
<P>Monit can monitor files for size changes and act on changes. This |
1093 |
options are:</P> |
options are:</P> |
1094 |
<PRE> |
<PRE> |
1095 |
TCPSSL [SSLAUTO|SSLV2|SSLV3|TLSV1] [CERTMD5 md5sum]</PRE> |
TCPSSL [SSLAUTO|SSLV2|SSLV3|TLSV1] [CERTMD5 md5sum]</PRE> |
1096 |
<P><STRONG>proto(col):PROTO {protcols}</STRONG>. Optionally specify the protocol |
<P><STRONG>proto(col):PROTO {protocols}</STRONG>. Optionally specify the protocol |
1097 |
monit should speak when a connection is established. At the |
monit should speak when a connection is established. At the |
1098 |
moment monit knows how to speak <EM>HTTP</EM>, <EM>SMTP</EM>, <EM>FTP</EM>, <EM>POP</EM>, |
moment monit knows how to speak <EM>HTTP</EM>, <EM>SMTP</EM>, <EM>FTP</EM>, <EM>POP</EM>, |
1099 |
<EM>IMAP</EM>, <EM>NNTP</EM>, <EM>SSH</EM>, <EM>DWP</EM>, <EM>LDAP2</EM>, <EM>LDAP3</EM>, <EM>RDATE</EM> |
<EM>IMAP</EM>, <EM>NNTP</EM>, <EM>SSH</EM>, <EM>DWP</EM>, <EM>LDAP2</EM>, <EM>LDAP3</EM>, <EM>RDATE</EM> |
1378 |
username and/or password are logged with their ip-address.</P> |
username and/or password are logged with their ip-address.</P> |
1379 |
<P> |
<P> |
1380 |
<HR> |
<HR> |
1381 |
<H1><A NAME="dependency tree">DEPENDENCY TREE</A></H1> |
<H1><A NAME="dependencies">DEPENDENCIES</A></H1> |
1382 |
<P>If specified in the control file, monit can do dependency |
<P>If specified in the control file, monit can do dependency |
1383 |
checking before start, stop, monitoring or unmonitoring of |
checking before start, stop, monitoring or unmonitoring of |
1384 |
services. The dependency statement may be used within any service |
services. The dependency statement may be used within any service |
1431 |
<P>A dependency tree is a general construct and can be used between |
<P>A dependency tree is a general construct and can be used between |
1432 |
all types of service entries and span many levels and propagate |
all types of service entries and span many levels and propagate |
1433 |
any supported action (except the exec action which will not |
any supported action (except the exec action which will not |
1434 |
propagate upward in a dependency tree for obvious reasons). Here |
propagate upward in a dependency tree for obvious reasons).</P> |
1435 |
is another example, based on a different perspective, but with a |
<P>Here is another different example. Consider the following common |
1436 |
depend tree as the baseline:</P> |
server setup:</P> |
|
<P>Consider the following common server setup:</P> |
|
1437 |
<PRE> |
<PRE> |
1438 |
WEB-SERVER -> APPLICATION-SERVER -> DATABASE -> FILESYSTEM |
WEB-SERVER -> APPLICATION-SERVER -> DATABASE -> FILESYSTEM |
1439 |
(a) (b) (c) (d)</PRE> |
(a) (b) (c) (d)</PRE> |
1822 |
<P>Here's a more advanced example for monitoring an apache |
<P>Here's a more advanced example for monitoring an apache |
1823 |
web-server listening on the default portnumber for HTTP and |
web-server listening on the default portnumber for HTTP and |
1824 |
HTTPS. In this example monit will restart apache if it's not |
HTTPS. In this example monit will restart apache if it's not |
1825 |
accepting connections at the portnumbers. The method monit use |
accepting connections at the port numbers. The method monit use |
1826 |
for a process restart is to first execute the stop-program, wait |
for a process restart is to first execute the stop-program, wait |
1827 |
for the process to stop and then execute the start-program. (If |
for the process to stop and then execute the start-program. (If |
1828 |
monit was unable to stop or start the service a failed alert |
monit was unable to stop or start the service a failed alert |