/[monit]/monit/web/monit.html
ViewVC logotype

Diff of /monit/web/monit.html

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.16 by hauk, Mon Feb 17 14:18:02 2003 UTC revision 1.17 by hauk, Fri Aug 29 16:58:07 2003 UTC
# Line 1  Line 1 
1  <HTML>  <HTML>
2  <HEAD>  <HEAD>
3  <TITLE>monit - system for monitoring programs</TITLE>  <TITLE>monit - utility for monitoring services on a Unix system</TITLE>
4  <LINK REV="made" HREF="mailto:bhcompile@daffy.perf.redhat.com">  <LINK REV="made" HREF="mailto:bhcompile@daffy.perf.redhat.com">
5  </HEAD>  </HEAD>
6    
7  <BODY BGCOLOR="#FFFFFF">  <BODY>
8    
9  <A NAME="__index__"></A>  <A NAME="__index__"></A>
10  <!-- INDEX BEGIN -->  <!-- INDEX BEGIN -->
# Line 31  Line 31 
31                  <LI><A HREF="#setting a global mail format">Setting a global mail format</A></LI>                  <LI><A HREF="#setting a global mail format">Setting a global mail format</A></LI>
32          </UL>          </UL>
33    
34          <LI><A HREF="#program timeout">PROGRAM TIMEOUT</A></LI>          <LI><A HREF="#service timeout">SERVICE TIMEOUT</A></LI>
35          <LI><A HREF="#resource testing">RESOURCE TESTING</A></LI>          <LI><A HREF="#resource testing">RESOURCE TESTING</A></LI>
36            <LI><A HREF="#file checksum testing">FILE CHECKSUM TESTING</A></LI>
37          <LI><A HREF="#timestamp testing">TIMESTAMP TESTING</A></LI>          <LI><A HREF="#timestamp testing">TIMESTAMP TESTING</A></LI>
38            <LI><A HREF="#file size testing">FILE SIZE TESTING</A></LI>
39          <LI><A HREF="#connection testing">CONNECTION TESTING</A></LI>          <LI><A HREF="#connection testing">CONNECTION TESTING</A></LI>
40            <UL>
41    
42                    <UL>
43    
44                            <UL>
45    
46                                    <LI><A HREF="#examples">Examples</A></LI>
47                            </UL>
48    
49                    </UL>
50    
51            </UL>
52    
53            <LI><A HREF="#space testing">SPACE TESTING</A></LI>
54            <LI><A HREF="#inode testing">INODE TESTING</A></LI>
55            <LI><A HREF="#permission testing">PERMISSION TESTING</A></LI>
56            <LI><A HREF="#uid testing">UID TESTING</A></LI>
57            <LI><A HREF="#gid testing">GID TESTING</A></LI>
58          <LI><A HREF="#monit httpd">MONIT HTTPD</A></LI>          <LI><A HREF="#monit httpd">MONIT HTTPD</A></LI>
59          <UL>          <UL>
60    
61                  <LI><A HREF="#monit httpd authentication">Monit HTTPD Authentication</A></LI>                  <LI><A HREF="#monit httpd authentication">Monit HTTPD Authentication</A></LI>
62          </UL>          </UL>
63    
         <LI><A HREF="#md5 checksum">MD5 CHECKSUM</A></LI>  
64          <LI><A HREF="#dependency checking">DEPENDENCY CHECKING</A></LI>          <LI><A HREF="#dependency checking">DEPENDENCY CHECKING</A></LI>
65          <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>
66          <UL>          <UL>
# Line 63  Line 82 
82  <HR>  <HR>
83  <P>  <P>
84  <H1><A NAME="name">NAME</A></H1>  <H1><A NAME="name">NAME</A></H1>
85  <P>monit - system for monitoring programs</P>  <P>monit - utility for monitoring services on a Unix system</P>
86  <P>  <P>
87  <HR>  <HR>
88  <H1><A NAME="synopsis">SYNOPSIS</A></H1>  <H1><A NAME="synopsis">SYNOPSIS</A></H1>
# Line 71  Line 90 
90  <P>  <P>
91  <HR>  <HR>
92  <H1><A NAME="description">DESCRIPTION</A></H1>  <H1><A NAME="description">DESCRIPTION</A></H1>
93  <P><STRONG>monit</STRONG> is a utility for monitoring and managing daemons or  <P><STRONG>Monit</STRONG> is a utility for monitoring and managing processes,
94  similar programs running on a Unix system; monit will start  files, directories and devices on a Unix system. Monit conducts
95  specified programs if they are not running and restart programs  automatic maintenance and repair and can execute meaningful
96  not responding.</P>  causal actions in error situations. E.g. monit can start a
97  <P>The monit utility can run in a daemon mode to repeatedly poll one  process if it does not run, restart a process if it does not
98  or more programs at a specified interval.</P>  respond and stop a process if it use to much resources. You may
99    use monit to monitor files, directories and devices for changes,
100    such as timestamps changes, checksum changes or size changes.</P>
101    <P>Monit is controlled via an easy to configure control file based
102    on a free-format, token-oriented syntax. Monit logs to syslog or
103    to its own log file and notifies you about error conditions via
104    customizable alert messages. Monit can perform various TCP/IP
105    network checks, protocol checks and can utilize SSL for such
106    checks. Monit provides a <CODE>HTTP(S)</CODE> interface and you may use a
107    browser to access the monit program.</P>
108  <P>  <P>
109  <HR>  <HR>
110  <H1><A NAME="general operation">GENERAL OPERATION</A></H1>  <H1><A NAME="general operation">GENERAL OPERATION</A></H1>
# Line 99  that you set the log and daemon options Line 127  that you set the log and daemon options
127     Print log information to this file</P>     Print log information to this file</P>
128  <P><STRONG>-p</STRONG> <EM>pidfile</EM>  <P><STRONG>-p</STRONG> <EM>pidfile</EM>
129     Use this lock file in daemon mode</P>     Use this lock file in daemon mode</P>
130    <P><STRONG>-s</STRONG> <EM>statefile</EM>
131       Write state information to this file</P>
132  <P><STRONG>-i</STRONG>  <P><STRONG>-i</STRONG>
133     Validate mode, startup in validate mode</P>     Validate mode, startup in validate mode</P>
134  <P><STRONG>-I</STRONG>  <P><STRONG>-I</STRONG>
135     Run from init (do not run in background)</P>     Run from init (do not run in background)</P>
136  <P><STRONG>-t</STRONG>  <P><STRONG>-t</STRONG>
137     Configuration syntax testing mode</P>     Run syntax check for the control file</P>
138  <P><STRONG>-v</STRONG>  <P><STRONG>-v</STRONG>
139     Verbose mode, work noisy (diagnostic output)</P>     Verbose mode, work noisy (diagnostic output)</P>
140  <P><STRONG>-V</STRONG>  <P><STRONG>-V</STRONG>
# Line 114  that you set the log and daemon options Line 144  that you set the log and daemon options
144  <P>In addition to the options above, monit can be started with one  <P>In addition to the options above, monit can be started with one
145  of the following action arguments; monit will then execute the  of the following action arguments; monit will then execute the
146  action and exit without transforming itself to a deamon.</P>  action and exit without transforming itself to a deamon.</P>
147  <P><STRONG>start</STRONG>  <P><STRONG>start all</STRONG>
148      Start all programs listed in the control file. If      Start all services listed in the control file and enable
149      the group option is set, only start the programs in      monitoring for them. If the group option is set, only
150      the named group.</P>      start and enable monitoring of services in the named group.</P>
151  <P><STRONG>start name</STRONG>  <P><STRONG>start name</STRONG>
152      Start the named program. The name must exist in the      Start the named service and enable monitoring for it. The
153      monitrc file, after a <EM>check</EM> keyword. See also      name must exist in the monitrc file, after a <EM>check</EM>
154      the MONIT HTTPD section below.</P>      keyword. See also the MONIT HTTPD section below.</P>
155  <P><STRONG>stop</STRONG>      <P><STRONG>stop all</STRONG>    
156      Stop all programs listed in the control file. If      Stop all services listed in the control file and disable
157      the group option is set, only stop the programs in      their monitoring. If the group option is set, only stop and
158      the named group.</P>      disable monitoring of the services in the named group.</P>
159  <P><STRONG>stop name</STRONG>  <P><STRONG>stop name</STRONG>
160      Stop the named program. The name must exist in the      Stop the named service and disable its monitoring. The name
161      monitrc file, after a <EM>check</EM> keyword. See also      must exist in the monitrc file, after a <EM>check</EM> keyword.
162      the MONIT HTTPD section below.</P>      See also the MONIT HTTPD section below.</P>
163  <P><STRONG>reload</STRONG>  <P><STRONG>restart all</STRONG>
164      Reinitialize a running monit daemon, the daemon will      Stop and start <EM>all</EM> services. If the group option is
165      reread its configuration, close and reopen log files.</P>      set, only restart the services in the named group.</P>
 <P><STRONG>restart</STRONG>  
     Stop and start <EM>all</EM> programs. If the group option is  
     set, only restart the programs in the named group.</P>  
166  <P><STRONG>restart name</STRONG>  <P><STRONG>restart name</STRONG>
167      Restart the named program. The name must exist in      Restart the named service. The name must exist in
168      the monitrc file, after a <EM>check</EM> keyword. also      the monitrc file, after a <EM>check</EM> keyword. also
169      the MONIT HTTPD section below.</P>      the MONIT HTTPD section below.</P>
170    <P><STRONG>monitor all</STRONG>    
171        Enable monitoring of all services listed in the
172        control file. If the group option is set, only start
173        the services monitoring in the named group.</P>
174    <P><STRONG>monitor name</STRONG>
175        Enable monitoring of the named service. The name must
176        exist in the monitrc file, after a <EM>check</EM> keyword.
177        Monit will enable monitoring of all services chain which
178        this service depends on before actualy starting monitoring
179        of this service. See also the MONIT HTTPD section below.</P>
180    <P><STRONG>unmonitor all</STRONG>    
181        Disable monitoring of all services listed in the
182        control file. If the group option is set, only stop
183        the services monitoring in the named group.</P>
184    <P><STRONG>unmonitor name</STRONG>
185        Disable monitoring of the named service. The name must
186        exist in the monitrc file, after a <EM>check</EM> keyword.
187        Monit will disable monitoring of the whole services chain
188        which depends on this service before actualy stopping
189        monitoring of this service. See also the MONIT HTTPD
190        section below.</P>
191  <P><STRONG>status</STRONG>  <P><STRONG>status</STRONG>
192      Print status information for each program. If the      Print status information for each service. If the
193      group option is set, only print the status for the      group option is set, only print the status for the
194      named group.</P>      named group.</P>
195    <P><STRONG>reload</STRONG>
196        Reinitialize a running monit daemon, the daemon will
197        reread its configuration, close and reopen log files.</P>
198  <P><STRONG>quit</STRONG>  <P><STRONG>quit</STRONG>
199      Kill monit daemon process</P>      Kill monit daemon process</P>
200  <P><STRONG>validate</STRONG>  <P><STRONG>validate</STRONG>
201      Check all programs and start the ones not running.      Check all services and start the ones not running.
202      Also if a program indicates (in the control file)      Also if a process indicates (in the control file)
203      that it's listening on a port number, although      that it's listening on a port number, although
204      monit cannot connect to the port, then restart the      monit cannot connect to the port, then restart the
205      program. This action is also the default      process. This action is also the default
206      behavior when monit runs in daemon mode.</P>      behavior when monit runs in daemon mode.</P>
207  <P>  <P>
208  <HR>  <HR>
# Line 169  file (and of course, do not use the -l s Line 220  file (and of course, do not use the -l s
220  specify a numeric argument which is a polling interval in  specify a numeric argument which is a polling interval in
221  seconds.</P>  seconds.</P>
222  <P>In daemon mode, monit puts itself in the background and runs  <P>In daemon mode, monit puts itself in the background and runs
223  continously, monitoring each specified program and then sleeping  continously, monitoring each specified service and then sleeping
224  for the given polling interval.</P>  for the given polling interval.</P>
225  <PRE>  <PRE>
226         Simply invoking</PRE>         Simply invoking</PRE>
227  <PRE>  <PRE>
228                monit -d 300</PRE>                monit -d 300</PRE>
229  <P>will poll all programs described in your <EM>~/.monitrc</EM> file every  <P>will poll all services described in your <EM>~/.monitrc</EM> file every
230  5 minutes.</P>  5 minutes.</P>
231  <P>It is possible to set a polling interval in your ~/.monitrc file  <P>It is possible and recommended to set a polling interval in your
232  by saying 'set daemon <STRONG>n</STRONG>', where <STRONG>n</STRONG> is an integer number of  ~/.monitrc file by saying 'set daemon <STRONG>n</STRONG>', where <STRONG>n</STRONG> is an
233  seconds.  If you do this, monit will always start in daemon mode  integer number of seconds.  If you do this, monit will always
234  (as long as no action arguments are given).</P>  start in daemon mode (as long as no action arguments are given).</P>
235  <P>Only one daemon process is permitted per user; in daemon mode,  <P>Monit makes a per-instance lockfile in daemon mode. If you need
236  monit makes a per-user lockfile to guarantee this.</P>  more monit instances, you will need more configuration files,
237    each pointing to its own lockfile.</P>
238  <P>Calling monit with a daemon in the background sends a wakeup  <P>Calling monit with a daemon in the background sends a wakeup
239  signal to the daemon, forcing it to check programs immediately.</P>  signal to the daemon, forcing it to check services immediately.</P>
240  <P>The <EM>quit</EM> argument will kill a running daemon process instead  <P>The <EM>quit</EM> argument will kill a running daemon process instead
241  of waking it up.</P>  of waking it up.</P>
242  <P>  <P>
# Line 213  monit in your startup scripts as well.</ Line 265  monit in your startup scripts as well.</
265  <P>  <P>
266  <HR>  <HR>
267  <H1><A NAME="group support">GROUP SUPPORT</A></H1>  <H1><A NAME="group support">GROUP SUPPORT</A></H1>
268  <P>Program entries in the control file, <EM>monitrc</EM>, can be grouped  <P>Service entries in the control file, <EM>monitrc</EM>, can be grouped
269  together by the <EM>group</EM> statement. The syntax is simply (keyword  together by the <EM>group</EM> statement. The syntax is simply (keyword
270  in capital):</P>  in capital):</P>
271  <PRE>  <PRE>
272    GROUP groupname</PRE>    GROUP groupname</PRE>
273  <P>With this statement it is possible to group similar program  <P>With this statement it is possible to group similar service
274  entries together and manage them as a whole. Monit provides  entries together and manage them as a whole. Monit provides
275  functions to start, stop and restart a group of programs, like  functions to start, stop and restart a group of services, like
276  so:</P>  so:</P>
277  <P>To start a group of programs:</P>  <P>To start a group of services:</P>
278  <PRE>  <PRE>
279    monit -g &lt;groupname&gt; start</PRE>    monit -g &lt;groupname&gt; start</PRE>
280  <P>To stop a group of programs:</P>  <P>To stop a group of services:</P>
281  <PRE>  <PRE>
282    monit -g &lt;groupname&gt; stop</PRE>    monit -g &lt;groupname&gt; stop</PRE>
283  <P>To restart a group of programs:</P>  <P>To restart a group of services:</P>
284  <PRE>  <PRE>
285    monit -g &lt;groupname&gt; restart</PRE>    monit -g &lt;groupname&gt; restart</PRE>
286  <P>Show the status of a program group:</P>  <P>Show the status of a service group:</P>
287  <PRE>  <PRE>
288    monit -g &lt;groupname&gt; status</PRE>    monit -g &lt;groupname&gt; status</PRE>
289  <P>  <P>
# Line 248  specifically <STRONG>not</STRONG> try to Line 300  specifically <STRONG>not</STRONG> try to
300  alerts in case of a problem.</P>  alerts in case of a problem.</P>
301  <P>For use in clustered environments there is also a <EM>manual</EM>  <P>For use in clustered environments there is also a <EM>manual</EM>
302  mode. In this mode, monit will enter <EM>active</EM> mode <STRONG>only</STRONG> if a  mode. In this mode, monit will enter <EM>active</EM> mode <STRONG>only</STRONG> if a
303  service was started under monit's control, for example by:</P>  service was brough under monit's control, for example by:</P>
304  <PRE>  <PRE>
305    monit start sybase</PRE>    monit start sybase (it will call start method and enable
306                          monitoring)</PRE>
307  <P>or</P>  <P>or</P>
308  <PRE>  <PRE>
309    monit -g database start (for service group)</PRE>    monit -g database start (for service group)</PRE>
310  <P>If the service wasn't started by monit or was stopped for example  <P>or</P>
311  by:</P>  <PRE>
312      monit monitor sybase (it will just enable monitoring)</PRE>
313    <P>or</P>
314  <PRE>  <PRE>
315    monit stop sybase</PRE>    monit -g database monitor (for service group)</PRE>
316    <P>If the service wasn't started by monit or was stopped or
317    disabled for example by:</P>
318    <PRE>
319      monit stop sybase (it will call stop method and disable
320                         monitoring)</PRE>
321  <P>or</P>  <P>or</P>
322  <PRE>  <PRE>
323    monit -g database stop (for service group)</PRE>    monit -g database stop (for service group)</PRE>
324    <P>or</P>
325    <PRE>
326      monit unmonitor sybase (it will just disable monitoring)</PRE>
327    <P>or</P>
328    <PRE>
329      monit -g database unmonitor (for service group)</PRE>
330  <P>monit will not monitor the service at all. This allows for having  <P>monit will not monitor the service at all. This allows for having
331  services configured in monitrc and start it with monit only if it  services configured in monitrc and start it with monit only if it
332  should run. This can be used to build simple failsafe clusters.  should run. This can be used to build simple failsafe clusters.
# Line 271  using the <EM>heartbeat</EM> system in t Line 337  using the <EM>heartbeat</EM> system in t
337  <H1><A NAME="alert messages">ALERT MESSAGES</A></H1>  <H1><A NAME="alert messages">ALERT MESSAGES</A></H1>
338  <P>monit will raise an email alert if:</P>  <P>monit will raise an email alert if:</P>
339  <PRE>  <PRE>
340   o A program timed out   o A service timed out
341   o A program was restarted   o A service was stopped
342   o A program was stopped   o A service monitoring was disabled (unmonitor)
343     o A port connection failed
344     o A resource statement match
345     o A permission error occurred
346     o A file checksum was changed
347   o A timestamp test didn't pass   o A timestamp test didn't pass
348   o A resource statement match (see also the section RESOURCE   o A file size test didn't pass
349     TESTING below)   o A service was started or restarted
350   o A checksum error occurred (see also the section MD5 CHECKSUM   o A file/directory/device uid error occurred
351     below)</PRE>   o A file/directory/device gid error occurred</PRE>
352  <P>More than one alert statement can be used in a process entry.  <P>More than one alert statement can be used in a service entry.
353  This means that you can send different emails to different  This means that you can send different emails to different
354  addresses. The full syntax for the alert statement is as  addresses. The full syntax for the alert statement is as
355  follows (keywords are in capital):</P>  follows (keywords are in capital):</P>
# Line 289  follows (keywords are in capital):</P> Line 359  follows (keywords are in capital):</P>
359  <PRE>  <PRE>
360   alert foo@bar</PRE>   alert foo@bar</PRE>
361  <P>will send a default email alert to the address foo@bar whenever a  <P>will send a default email alert to the address foo@bar whenever a
362  timeout, restart, checksum, resource, stop or timestamp error  timeout, start, restart, checksum, resource, stop, connection, size,
363  occurs.</P>  permission, uid, gid, unmonitor or timestamp error occurs.</P>
364  <P>If you only want an alert message sent when a certain event  <P>If you only want an alert message sent when a certain event
365  occurs for example a timeout or when a program is restarted,  occurs for example a timeout or when a service is restarted,
366  postfix the alert-statement respectively</P>  postfix the alert-statement respectively</P>
367  <PRE>  <PRE>
368   alert foo@bar only on { timeout } or   alert foo@bar only on { timeout } or
# Line 307  postfix the alert-statement respectively Line 377  postfix the alert-statement respectively
377  <P>It is also possible to combine events and send mail to different  <P>It is also possible to combine events and send mail to different
378  email addresses like:</P>  email addresses like:</P>
379  <PRE>  <PRE>
380   alert foo@bar { restart, timeout, resource }   alert foo@bar { restart, timeout, resource, connection,
381   alert security@bar on { checksum, stop }                   unmonitor }
382     alert security@bar on { checksum, permission, uid, gid,
383                             stop, unmonitor }
384   alert manager@bar</PRE>   alert manager@bar</PRE>
385  <P>This will send an alert message to foo@bar when a timeout,  <P>This will send an alert message to foo@bar whenever a restart,
386  resource or restart occurs and a message to security@bar if a  timeout, resource or connection error occurs and a message to
387  checksum error or stop occurs. And finally, a message to  security@bar if a checksum, permission, uid, gid or stop error
388  manager@bar whenever any error event occurs.  occurs.  And finally, a message to manager@bar whenever any
389    error event occurs.
390  </P>  </P>
391  <PRE>  <PRE>
392    
393  The following alert-statement:</PRE>  The following alert-statement:</PRE>
394  <PRE>  <PRE>
395    
396   alert foo@bar { timeout   alert foo@bar {checksum
397                   restart                  connection
398                   checksum                  gid
399                   resource                  permission
400                   stop                  resource
401                   timestamp }</PRE>                  restart
402                    start
403                    size
404                    stop
405                    timeout
406                    timestamp
407                    uid
408                    unmonitor}</PRE>
409  <P>is equivalent to:</P>  <P>is equivalent to:</P>
410  <PRE>  <PRE>
411   alert foo@bar</PRE>   alert foo@bar</PRE>
412  <P>which as stated above, will send a message when a timeout, a  <P>which as stated above, will send a message whenever a timeout, a
413  restart, checksum, resource, stop or timestamp error occurs.  (If  start, restart, checksum, resource, stop, connection, size,
414    permission, uid, gid, unmonitor or timestamp error occurs. (If
415  the postfix variant is used, then note that the parenthesis are  the postfix variant is used, then note that the parenthesis are
416  <EM>mandatory</EM>).</P>  <EM>mandatory</EM>).</P>
417  <P>A restart alert is also sent <EM>if monit fails to execute</EM> a start  <P>A start, stop or restart alert is also sent <EM>if monit fails to
418  or stop program for an entry. <STRONG>It is therefor strongly advised</STRONG>  execute</EM> a start or stop program for an entry. <STRONG>It is therefore
419  that at least one alert statement register interest for restart  strongly advised</STRONG> that at least one alert statement register
420  alerts.</P>  interest for either, start, stop or restart alerts.</P>
421  <P>monit will provide a default mail message layout that is short  <P>monit will provide a default mail message layout that is short
422  and to the point. Here's an example of a standard alert mail sent  and to the point. Here's an example of a standard alert mail sent
423  by monit:</P>  by monit:</P>
424  <PRE>  <PRE>
425   From: monit@tildeslash.com   From: monit@tildeslash.com
426   Subject: monit alert -- apache restarted   Subject: monit alert -- Restarted apache
427   To: hauk@tildeslash.com   To: hauk@tildeslash.com
428   Date: Tue, 28 May 2002 20:42:30 +0200</PRE>   Date: Mon, 04 Aug 2003 06:26:54 +0200</PRE>
429  <PRE>  <PRE>
430   Program apache restarted</PRE>   Restarted Service apache</PRE>
431  <PRE>  <PRE>
432          Date: Tue May 28 20:42:30 2002          Date: Tue May 28 20:42:30 2002
433          Host: www.tildeslash.com</PRE>          Host: www.tildeslash.com</PRE>
# Line 360  statement is as follows:</P> Line 441  statement is as follows:</P>
441   mail-format {   mail-format {
442        from: monit@localhost        from: monit@localhost
443     subject: apache $EVENT at $DATE     subject: apache $EVENT at $DATE
444     message: Monit restarted $PROGRAM at $DATE on $HOST.     message: Monit restarted $SERVICE at $DATE on $HOST.
445              Yours sincerely,              Yours sincerely,
446              monit              monit
447   }</PRE>   }</PRE>
448  <P>Where the keyword <EM>from:</EM> is the email address monit should  <P>Where the keyword <EM>from:</EM> is the email address monit should
449  pretend it is sending from. It does not have to be a real mail  pretend it is sending from. It does not have to be a real mail
450  address, but must be a proper formated mail address, on the form;  address, but must be a proper formated mail address, in the form:
451  name@domain. The keyword <EM>subject:</EM> is for the email subject  name@domain. The keyword <EM>subject:</EM> is for the email subject
452  line. The subject must be on only <EM>one</EM> line. The <EM>message:</EM>  line. The subject must be on only <EM>one</EM> line. The <EM>message:</EM>
453  keyword denotes the mail body. If used, this keyword should  keyword denotes the mail body. If used, this keyword should
# Line 381  is using you can do:</P> Line 462  is using you can do:</P>
462  variables was used. If used they will be substituted into the  variables was used. If used they will be substituted into the
463  text with a special value:</P>  text with a special value:</P>
464  <P><EM>$EVENT</EM> A string describing the event that occured. The values  <P><EM>$EVENT</EM> A string describing the event that occured. The values
465  are fixed and are, ``restarted'', ``timed out'', ``stopped and  are fixed and are, ``Started'', ``Stopped'', ``Restarted'', Checksum
466  ''checksum error``</P>  error``, ''Resource limit matched``, ''Timeout``, ''Size rule matched``,
467  <P><EM>$PROGRAM</EM> The program entry name in monitrc</P>  ''Permission error``, ''Connection test failed``, ''UID error``, ''GID
468  <P><EM>$DATE</EM> The current time and date (C time style).</P>  error``, ''Monitoring disabled`` and ''Timestamp rule matched``.</P>
469    <P><EM>$SERVICE</EM> The service entry name in monitrc (old form
470    <EM>$PROGRAM</EM> is supported too but not recommended).</P>
471    <P><EM>$DATE</EM> The current time and date (RFC 822 date style).</P>
472  <P><EM>$HOST</EM> The name of the host monit is running on</P>  <P><EM>$HOST</EM> The name of the host monit is running on</P>
473  <P>  <P>
474  <H2><A NAME="setting a global mail format">Setting a global mail format</A></H2>  <H2><A NAME="setting a global mail format">Setting a global mail format</A></H2>
# Line 402  for messages sent by monit, like so:</P> Line 486  for messages sent by monit, like so:</P>
486   set mail-format { from: monit@foo.bar.no }</PRE>   set mail-format { from: monit@foo.bar.no }</PRE>
487  <P>  <P>
488  <HR>  <HR>
489  <H1><A NAME="program timeout">PROGRAM TIMEOUT</A></H1>  <H1><A NAME="service timeout">SERVICE TIMEOUT</A></H1>
490  <P><STRONG>monit</STRONG> provides a program timeout mechanism for situations  <P><STRONG>monit</STRONG> provides a service timeout mechanism for situations
491  where a program simply refuses to start or respond over a longer  where a service simply refuses to start or respond over a longer
492  period. In cases like this, and particularly if monits poll-cycle  period. In cases like this, and particularly if monits poll-cycle
493  is low, monit will simply increase the machine load by trying to  is low, monit will simply increase the machine load by trying to
494  restart the program.</P>  restart the service.</P>
495  <P>The timeout mechanism monit provides is based on two variables,  <P>The timeout mechanism monit provides is based on two variables,
496  i.e. the number the program has been started and the number of  i.e. the number the service has been started and the number of
497  poll-cycles. For example, if a program had <EM>x</EM> restarts within  poll-cycles. For example, if a service had <EM>x</EM> restarts within
498  <EM>y</EM> poll-cycles (where <EM>x</EM> &lt;= <EM>y</EM>) then monit will timeout and  <EM>y</EM> poll-cycles (where <EM>x</EM> &lt;= <EM>y</EM>) then monit will timeout and
499  not (re)start the program on the next cycle. It's a good idea to  not (re)start the service on the next cycle. If a timeout occurs
500  use the alert statement in conjunction with timeout, so if a  monit will send you an alert message if you have register
501  timeout occurs monit will send an alert notification. A legal  interest for this event. See the alert statement above to learn
502  (but verbose) way to write a timeout statement for a program  how you may recieve timeout alert messages.</P>
503  entry in the control file is:</P>  <P>The syntax for the timestamp statement is as follows (keywords
504  <PRE>  are in capital):</P>
505   timeout if 3 restarts within 3 cycles</PRE>  <DL>
506  <P>The shorthand version is:</P>  <DT><STRONG><A NAME="item_IF_NUMBER_RESTART_NUMBER_CYCLE_THEN_TIMEOUT">IF NUMBER RESTART NUMBER CYCLE THEN TIMEOUT</A></STRONG><BR>
507  <PRE>  <DD>
508   timeout(3,3)</PRE>  </DL>
509  <P>Where the first digit is the number of program restarts, the  <P>Where the first number is the number of service restarts, the
510  second is the number of poll-cycles. If the number of cycles was  second is the number of poll-cycles. If the number of cycles was
511  reached without a timeout, the program start-counter is reset to  reached without a timeout, the service start-counter is reset to
512  zero. This provides some granularity to catch expectional cases  zero. This provides some granularity to catch expectional cases
513  and do a program timeout, but to let occasional program restarts  and do a service timeout, but let occasional service start and
514  happen without having an accumulated timeout.</P>  restarts happen without having an accumulated timeout.</P>
515  <P>If you use timeout (it's optional), then be sure to add an alert  <P>Here is an example where monit will timeout (not check the
516  statement to notify the responsible administrator. Such as:  service) if the service was restarted 2 times within 3 cycles:</P>
517  </P>  <PRE>
518  <PRE>   if 2 restarts within 3 cycles then timeout</PRE>
519    <P>To have monit check the service again after a timeout, run 'monit
520   timeout(3, 5) and alert bofh@foo.bar on { timeout }</PRE>  start service' from the command line. This will remove the
 <P>To have monit check the program again after a timeout, run 'monit  
 start program' from the command line. This will remove the  
521  timeout lock in the daemon and make the daemon start and check  timeout lock in the daemon and make the daemon start and check
522  the program again.</P>  the service again.</P>
523  <P>  <P>
524  <HR>  <HR>
525  <H1><A NAME="resource testing">RESOURCE TESTING</A></H1>  <H1><A NAME="resource testing">RESOURCE TESTING</A></H1>
# Line 449  systems which are idle and to spare syst Line 531  systems which are idle and to spare syst
531  <P>The full syntax for the resource-statements used for resource  <P>The full syntax for the resource-statements used for resource
532  testing is as follows (keywords are in capital and optional  testing is as follows (keywords are in capital and optional
533  statements in [brackets]),</P>  statements in [brackets]),</P>
534  <PRE>  <DL>
535   resource operator value [cycles] action</PRE>  <DT><STRONG><A NAME="item_IF_resource_operator_value_%5Bcycles%5D_THEN_actio">IF resource operator value [cycles] THEN action</A></STRONG><BR>
536  <P><EM>resource</EM> is a choice of ``CPUUSAGE'', ``MEMUSAGE'', ``MEMKBYTE'',  <DD>
537  ``LOADAVG([1min|5min|15min])'':</P>  </DL>
538  <P>CPUUSAGE is the CPU usage of the process and it's children in  <P><EM>resource</EM> is a choice of ``CPU'', ``MEMORY'', ``CHILDREN'',
539  parts of hundred (percent). This resource <EM>value</EM> is a floating  ``TOTALMEMORY'', ``LOADAVG([1min|5min|15min]):</P>
540  point number. For instance, 60.0.</P>  <P>CPU is the CPU usage of the process and it's children in
541  <P>MEMUSAGE is the memory usage of the process in parts of hundred  parts of hundred (percent).</P>
542  (percent). This resource <EM>value</EM> is also a floating point  <P>MEMORY is the memory usage of the process without it's child
543  number.</P>  processes in wheather in parts of hundred (percent) or as an
544  <P>MEMKBYTE is the memory amount of the process in KiB (1024  amount (Byte, kB, MB, GB).</P>
545  byte). This resource <EM>value</EM> is an integer number.</P>  <P>CHILDREN is the number of child processes of the process.</P>
546    <P>TOTALMEMORY is the memory usage of the process and it's child
547    processes in whether in parts of hundred (percent) or as an
548    amount (Byte, kB, MB, GB).</P>
549  <P><CODE>LOADAVG([1min|5min|15min])</CODE> refers to the system's load average.  <P><CODE>LOADAVG([1min|5min|15min])</CODE> refers to the system's load average.
550  The load average is the number of processes in the system run  The load average is the number of processes in the system run
551  queue averaged over the specified time period. This resource  queue averaged over the specified time period. This resource</P>
 <EM>value</EM> is again a floating point number.</P>  
552  <P><EM>operator</EM> is a choice of ``&lt;'',``&gt;'',``!='',``=='' in c notation, ``gt'',  <P><EM>operator</EM> is a choice of ``&lt;'',``&gt;'',``!='',``=='' in c notation, ``gt'',
553  ``lt'', ``eq'', ``ne'' in shell sh notation and ``greater'', ``less'',  ``lt'', ``eq'', ``ne'' in shell sh notation and ``greater'', ``less'',
554  ``equal'', ``notequal'' in human readable form (if not specified,  ``equal'', ``notequal'' in human readable form (if not specified,
555  default is EQUAL).</P>  default is EQUAL).</P>
556    <P><EM>value</EM> is whether an integer number or a fixed point number
557    (except for CHILDREN).  For CPU, MEMORY and TOTALMEMORY you need
558    to specify a <EM>unit</EM>.  This could be ``%'' or if applicable ``B''
559    (Byte), ``kB'' (1024 Byte), ``MB'' (1024 KiloByte) or ``GB'' (1024
560    MegaByte).</P>
561  <P><EM>cycles</EM> is the maximum number of cycles the expression above  <P><EM>cycles</EM> is the maximum number of cycles the expression above
562  has to be true in order to start an action.  If <EM>cycles</EM> is  has to be true in order to start an action.  If <EM>cycles</EM> is
563  omitted then it is set to one.</P>  omitted then it is set to one.</P>
564  <P><EM>action</EM> is a choice of ``ALERT'', ``RESTART'', ``STOP'':</P>  <P><EM>action</EM> is a choice of ``ALERT'', ``RESTART'', ``STOP'', ``EXEC'' or
565  <P>ALERT sends the user a resource alert in case the maximum number  ``UNMONITOR'':</P>
566  of cycles has been reached.</P>  <UL>
567  <P>RESTART restarts the service in case the maximum number of cycles  <LI>
568  has been reached.</P>  ALERT ALERT sends the user a resource alert in case the maximum
569  <P>STOP stops the service in case the maximum number of cycles has  number of cycles has been reached.
570  been reached. If monit stops a service it will not be checked by  <P></P>
571  monit anymore nor restarted again later. You must explicit start  <LI>
572  it again from the web interface or from the console, like: 'monit  RESTART restarts the service in case the maximum number of cycles
573  start apache' if you want the monit daemon to monitor the service  has been reached.
574  again.</P>  <P></P>
575    <LI>
576    STOP stops the service. If monit stops a service it will not be
577    checked by monit anymore nor restarted again later. You must
578    explicitly start it again from the web interface or from the
579    console, like: 'monit start apache' or 'monit monitor apache'
580    if you want the monit daemon to monitor the service again.
581    <P></P>
582    <LI>
583    EXEC may be used to execute an arbitrary program. If you choose
584    this action you must state the program to be executed. For
585    instance; exec ``/etc/init.d/network restart''
586    <P></P>
587    <LI>
588    UNMONITOR will disable monitoring of the service - it will not be
589    checked by monit anymore nor restarted again later. The chain of
590    all services which depends on this service will be unmonitored
591    before this service monitoring will be stopped. You can enable
592    monitoring again either via console 'monitor' command, via web
593    interface or use 'start' command, which will enable the
594    monitoring too.
595    <P></P></UL>
596  <P>To calculate the cycles, a counter is raised whenever the  <P>To calculate the cycles, a counter is raised whenever the
597  expression above is true and it is lowered whenever it is false  expression above is true and it is lowered whenever it is false
598  (but not below 0).  All counters are reseted in case of a  (but not below 0). All counters are reseted in case of a restart.</P>
 restart.</P>  
599  <P>In order to check that the CPU usage of a service is not going  <P>In order to check that the CPU usage of a service is not going
600  beyond 50% for five cycles before restarting it, the following  beyond 50% for five cycles before restarting it, the following
601  expression could be used:</P>  expression could be used:</P>
602  <PRE>  <PRE>
603   if cpuusage is greater than 50.0 for 5 cycles then restart</PRE>   if cpu is greater than 50% for 5 cycles then restart</PRE>
 <P>Or the short version without noise keywords:</P>  
 <PRE>  
  cpuusage &gt; 50.0 5 restart</PRE>  
604  <P>See also the example section below.</P>  <P>See also the example section below.</P>
605  <P>  <P>
606  <HR>  <HR>
607    <H1><A NAME="file checksum testing">FILE CHECKSUM TESTING</A></H1>
608    <P>If specified in the control file, monit will compute a md5
609    checksum for a file. The checksum is used to verify that a file
610    does not change. The checksum statement may <STRONG>only</STRONG> be used in a
611    file service entry.</P>
612    <P>The full syntax for the checksum statement is as follows:
613    (keywords are in capital)</P>
614    <DL>
615    <DT><STRONG><A NAME="item_IF_FAILED_CHECKSUM_%5BEXPECT_checksum%5D_THEN_acti">IF FAILED CHECKSUM [EXPECT checksum] THEN action</A></STRONG><BR>
616    <DD>
617    </DL>
618    <P><EM>expect</EM> is optional and if used specifies a md5 string monit
619    should expect when testing a file's checksum. If <EM>expect</EM> is
620    used monit will not compute an initial checksum for the file, but
621    instead use the string you submit. For example:</P>
622    <PRE>
623     if failed checksum and
624        expect the sum 8f7f419955cefa0b33a2ba316cba3659
625     then alert</PRE>
626    <P>You can, for example, use the GNU utility <EM>md5sum</EM> to create a
627    checksum string for a file and then use this string in the
628    expect-statement.</P>
629    <P><EM>action</EM> is a choice of ``ALERT'', ``RESTART'', ``STOP'', ``EXEC'' or
630    ``UNMONITOR'':</P>
631    <UL>
632    <LI>
633    ALERT sends the user a checksum alert.
634    <P></P>
635    <LI>
636    RESTART restarts the service <EM>and</EM> sends an alert.
637    <P></P>
638    <LI>
639    STOP stops the service <EM>and</EM> sends an alert. If monit stops a
640    service it will not be checked by monit anymore nor restarted
641    again later. You must explicit start it again from the web
642    interface or from the console, like: 'monit start myfile' or
643    'monit monitor myfile' if you want the monit daemon to monitor
644    the service again.
645    <P></P>
646    <LI>
647    EXEC may be used to execute an arbitrary program <EM>and</EM> send an
648    alert. If you choose this action you must state the program to be
649    executed. For instance; exec ``/sbin/ifconfig eth0 down''.
650    <P></P>
651    <LI>
652    UNMONITOR will disable monitoring of the service - it will not be
653    checked by monit anymore nor restarted again later. The chain of
654    all services which depends on this service will be unmonitored
655    before this service monitoring will be stopped. You can enable
656    monitoring again either via console 'monitor' command, via web
657    interface or use 'start' command, which will enable the
658    monitoring too.
659    <P></P></UL>
660    <P>The checksum statement may be used to check a file for changes
661    and if changed, do a specified action. For instance to reload a
662    server if its configuration file was changed. The following
663    illustrate this for the apache web server:</P>
664    <PRE>
665     check file httpd.conf path /usr/local/apache/conf/httpd.conf
666      if failed checksum
667      then exec &quot;/usr/local/apache/bin/apachectl -k restart&quot;</PRE>
668    <P><STRONG>Note</STRONG>, if you plan to use the checksum statement for security
669    reasons, e.g. to monitor a file which should not change, then we
670    strongly recommend that you choose the <EM>unmonitor</EM> action.  The
671    reason is that you may accidentally execute a cracked program if
672    a service depends on the file-service containing the checksum
673    test, as in this example:</P>
674    <PRE>
675     check apache with pidfile &quot;/usr/local/apache/logs/httpd.pid&quot;
676      start program = &quot;/usr/local/apache/bin/http start&quot;
677      stop program  = &quot;/usr/local/apache/bin/http stop&quot;
678      alert hauk@tildeslash.com
679      depends on http.bin</PRE>
680    <PRE>
681     check file http.bin path /usr/local/apache/bin/http
682      if failed checksum then stop</PRE>
683    <P>If /usr/local/apache/bin/http (in the above example) was changed
684    then the stop action in the checksum statement is executed, but
685    the stop action will also propagate upward in the dependency tree
686    and call the stop program for services that depends on the check
687    file service as well. Since we just found a checksum error in the
688    http binary we should absolutely not want to execute this
689    program, that is; the apache service's stop program.</P>
690    <P>In this example, you should instead choose the unmonitor action.
691    You will then disable monitoring of this service and all services
692    which depends on it and only get an alert message saying that
693    /usr/local/apache/bin/http was changed and you may then start
694    your own cognitive <STRONG>OODA</STRONG> loop, that is; Observe, Orient, Decide
695    and Act. In this case, where your system may be compromised, it's
696    better that you do this than monit.</P>
697    <P>
698    <HR>
699  <H1><A NAME="timestamp testing">TIMESTAMP TESTING</A></H1>  <H1><A NAME="timestamp testing">TIMESTAMP TESTING</A></H1>
700  <P>Monit can watch the timestamp of any file or directory associated  <P>Monit can monitor file, directories and devices for timestamp
701  with a program.</P>  changes. A timestamp test may only be used within a file or
702    directory entry in the monit control file.</P>
703    <P>The timestamp statement comes in two flavors. The first and basic
704    version is simply to test an existing file for timestamp changes
705    and if changed, execute an action. The second, and more compound,
706    version is used to test a file or directory for various timestamp
707    changes.</P>
708  <P>The full syntax for the timestamp statement is as follows  <P>The full syntax for the timestamp statement is as follows
709  (keywords are in capital and optional statements in [brackets]):</P>  (keywords are in capital and optional statements in [brackets]):</P>
710  <PRE>  <OL>
711   TIMESTAMP object [operator] value [unit] action</PRE>  <LI><STRONG><A NAME="item_IF_TIMESTAMP_was_CHANGED_THEN_action">IF TIMESTAMP was CHANGED THEN action</A></STRONG><BR>
712  <P><EM>object</EM> is a path to the associated file or directory to watch.</P>  
713    <LI><STRONG><A NAME="item_IF_TIMESTAMP_%5Boperator%5D_value_%5Bunit%5D_THEN_">IF TIMESTAMP [operator] value [unit] THEN action</A></STRONG><BR>
714    
715    </OL>
716  <P><EM>operator</EM> is a choice of ``&lt;'',``&gt;'',``!='',``=='' in c notation, ``GT'',  <P><EM>operator</EM> is a choice of ``&lt;'',``&gt;'',``!='',``=='' in c notation, ``GT'',
717  ``LT'', ``EQ'', ``NE'' in shell sh notation and ``GREATER'', ``LESS'',  ``LT'', ``EQ'', ``NE'' in shell sh notation and ``GREATER'', ``LESS'',
718  ``EQUAL'', ``NOTEQUAL'' in human readable form (if not specified,  ``EQUAL'', ``NOTEQUAL'' in human readable form (if not specified,
# Line 513  default is EQUAL).</P> Line 720  default is EQUAL).</P>
720  <P><EM>value</EM> is a time watermark.</P>  <P><EM>value</EM> is a time watermark.</P>
721  <P><EM>unit</EM> is either ``SECOND'', ``MINUTE'', ``HOUR'' or ``DAY'' (it is also  <P><EM>unit</EM> is either ``SECOND'', ``MINUTE'', ``HOUR'' or ``DAY'' (it is also
722  possible to use ``SECONDS'', ``MINUTES'', ``HOURS'', or ``DAYS'').</P>  possible to use ``SECONDS'', ``MINUTES'', ``HOURS'', or ``DAYS'').</P>
723  <P><EM>action</EM> is a choice of ``ALERT'', ``RESTART'', ``STOP'':</P>  <P><EM>action</EM> is a choice of ``ALERT'', ``RESTART'', ``STOP'', ``EXEC'' or
724  <PRE>  ``UNMONITOR'':</P>
725   o ALERT sends the user a timestamp alert.</PRE>  <UL>
726  <PRE>  <LI>
727   o RESTART restarts the service.</PRE>  ALERT sends the user a timestamp alert.
728  <PRE>  <P></P>
729   o STOP stops the service. If monit stops a service it will not  <LI>
730     be checked by monit anymore nor restarted again later. You  RESTART restarts the service.
731     must explicit start it again from the web interface or from  <P></P>
732     the console, like: 'monit start apache' if you want the monit  <LI>
733     daemon to monitor the service again.</PRE>  STOP stops the service. If monit stops a service it will
734  <P>The timestamp statement is useful for monitoring systems, that  not be checked by monit anymore nor restarted again later. You
735  are able to report its state by changing the timestamp of certain  must explicit start it again from the web interface or from the
736  state files. For instance the <EM>iPlanet Messaging server stored  console, like: 'monit start datafs' or 'monit monitor datafs'
737  process</EM> system update the timestamp of:</P>  if you want the monit daemon to monitor the service again.
738    <P></P>
739    <LI>
740    EXEC may be used to execute an arbitrary program. If you choose
741    this action you must state the program to be executed. For
742    instance; exec ``/bin/rm -f /tmp/foobar''
743    <P></P>
744    <LI>
745    UNMONITOR will disable monitoring of the service - it will not be
746    checked by monit anymore nor restarted again later. The chain of
747    all services which depends on this service will be unmonitored
748    before this service monitoring will be stopped. You can enable
749    monitoring again either via console 'monitor' command, via web
750    interface or use 'start' command, which will enable the
751    monitoring too.
752    <P></P></UL>
753    <P>The basic timestamp statement is useful for checking a file for
754    changes and then execute an action. This version was written
755    particularly with configuration files in mind. For instance, if
756    you monitor the apache web server you can use this statement to
757    reload apache if the <EM>httpd.conf</EM> (apache's configuration file)
758    was changed. Like so:</P>
759    <PRE>
760     check file httpd.conf with path /usr/local/apache/conf/httpd.conf
761       if timestamp was changed
762       then exec &quot;/usr/local/apache/bin/apachectl graceful&quot;</PRE>
763    <P>The second timestamp version is useful for monitoring systems,
764    that are able to report its state by changing the timestamp of
765    certain state files. For instance the <EM>iPlanet Messaging server
766    stored process</EM> system updates the timestamp of:</P>
767  <PRE>  <PRE>
768   o stored.ckp   o stored.ckp
769   o stored.lcu   o stored.lcu
# Line 536  process</EM> system update the timestamp Line 772  process</EM> system update the timestamp
772  timestamp.</P>  timestamp.</P>
773  <P>To report stored problems you can use following statements:</P>  <P>To report stored problems you can use following statements:</P>
774  <PRE>  <PRE>
775   if timestamp &quot;/msg-foo/config/stored.ckp&quot; &gt; 1 minute then alert   check file stored.ckp with path /msg-foo/config/stored.ckp
776   if timestamp &quot;/msg-foo/config/stored.lcu&quot; &gt; 5 minutes then alert     if timestamp &gt; 1 minute then alert</PRE>
777   if timestamp &quot;/msg-foo/config/stored.per&quot; &gt; 1 hour then alert</PRE>  <PRE>
778  <P>or the equivalent less verbose form:</P>   check file stored.lcu with path /msg-foo/config/stored.lcu
779  <PRE>     if timestamp 5 minutes then alert
780   timestamp &quot;/msg-foo/config/stored.ckp&quot; &gt; 60 alert  </PRE>
781   timestamp &quot;/msg-foo/config/stored.lcu&quot; &gt; 300 alert  <PRE>
782   timestamp &quot;/msg-foo/config/stored.per&quot; &gt; 3600 alert</PRE>  
783     check file stored.per with path /msg-foo/config/stored.per
784       if timestamp &gt; 1 hour then alert</PRE>
785  <P>As mentioned above, you can also use the timestamp statement for  <P>As mentioned above, you can also use the timestamp statement for
786  monitoring directories for changes. If files are added or removed  monitoring directories for changes. If files are added or removed
787  to/from a directory, its timestamp is changed:</P>  from a directory, it's timestamp is changed:</P>
788  <PRE>  <PRE>
789   if timestamp &quot;/foo/directory&quot; &gt; 1 hour then alert</PRE>   check directory mydir path /foo/directory
790      if timestamp &gt; 1 hour then alert</PRE>
791  <P>or</P>  <P>or</P>
792  <PRE>  <PRE>
793   if timestamp &quot;/foo/secure/directory&quot; &lt; 1 hour then alert</PRE>   check directory myotherdir path /foo/secure/directory
794      if timestamp &lt; 1 hour then alert</PRE>
795  <P>The following example is a neat trick for restarting a process  <P>The following example is a neat trick for restarting a process
796  after a certain time. Sometimes this is a necessary workaround  after a certain time. Sometimes this is a necessary workaround
797  for some products, until the vendor fix a problem:</P>  for some products, until the vendor fix a problem:</P>
798  <PRE>  <PRE>
799   if timestamp &quot;/var/run/crappy_program.pid&quot; &gt; 7 days then restart</PRE>   check file foobar.pid path /var/run/foobar.pid
800      if timestamp &gt; 7 days then exec &quot;/etc/init.d/foobar restart&quot;</PRE>
801  <P>  <P>
802  <HR>  <HR>
803  <H1><A NAME="connection testing">CONNECTION TESTING</A></H1>  <H1><A NAME="file size testing">FILE SIZE TESTING</A></H1>
804  <P>Monit is able to perfom connection testing via networked ports  <P>Monit can monitor files for size changes and act on such
805  and via unix sockets.</P>  changes. This test may only be used within a file service entry
806  <P>If a program listens on one or more sockets, monit can connect to  in the monit control file.</P>
807  the port (using either tcp or udp) and verify that the program  <P>The size statement comes in two flavors. The first and basic
808  will accept a connection and that it is possible to read and  version is simply to test an existing file for size changes and
809  write to the socket. If a connection is not accepted or if there  if changed, execute an action. The second, and more compound,
810  is a problem with the socket i|o, monit will assume that  version is used to test a file for various size changes.</P>
811  something is wrong and restart the program.  Additionally, if  <P>The full syntax for the size statement is as follows
812  monit is compiled with openssl support ssl forged network  (keywords are in capital and optional statements in [brackets]):</P>
813  services can be tested, too.</P>  <OL>
814  <P>The full syntax for the port-statement used for connection  <LI><STRONG><A NAME="item_IF_SIZE_was_CHANGED_THEN_action">IF SIZE was CHANGED THEN action</A></STRONG><BR>
815  testing is as follows (keywords are in capital and optional  
816  statements in [brackets]) for networked ports,</P>  <LI><STRONG><A NAME="item_IF_SIZE_%5Boperator%5D_value_%5Bunit%5D_THEN_actio">IF SIZE [operator] value [unit] THEN action</A></STRONG><BR>
817    
818    </OL>
819    <P><EM>operator</EM> is a choice of ``&lt;'',``&gt;'',``!='',``=='' in c notation, ``GT'',
820    ``LT'', ``EQ'', ``NE'' in shell sh notation and ``GREATER'', ``LESS'',
821    ``EQUAL'', ``NOTEQUAL'' in human readable form (if not specified,
822    default is EQUAL).</P>
823    <P><EM>value</EM> is a size watermark.</P>
824    <P><EM>unit</EM> is a choice of ``B'',``KB'',``MB'',``GB'' or long alternatives
825    ``byte'', ``kilobyte'', ``megabyte'', ``gigabyte''. If it is not specified,
826    ``byte'' unit is assumed by default.</P>
827    <P><EM>action</EM> is a choice of ``ALERT'', ``RESTART'', ``STOP'', ``EXEC'' or
828    ``UNMONITOR'':</P>
829    <UL>
830    <LI>
831    ALERT sends the user a size alert.
832    <P></P>
833    <LI>
834    RESTART restarts the service.
835    <P></P>
836    <LI>
837    STOP stops the service. If monit stops a service it will
838    not be checked by monit anymore nor restarted again later. You
839    must explicit start it again from the web interface or from the
840    console, like: 'monit start myfile' or 'monit monitor myfile'
841    if you want the monit daemon to monitor the service again.
842    <P></P>
843    <LI>
844    EXEC may be used to execute an arbitrary program. If you choose
845    this action you must state the program to be executed. For
846    instance; exec ``/bin/rm -f /tmp/foobar''
847    <P></P>
848    <LI>
849    UNMONITOR will disable monitoring of the service - it will not be
850    checked by monit anymore nor restarted again later. The chain of
851    all services which depends on this service will be unmonitored
852    before this service monitoring will be stopped. You can enable
853    monitoring again either via console 'monitor' command, via web
854    interface or use 'start' command, which will enable the
855    monitoring too.
856    <P></P></UL>
857    <P>The basic size statement is useful for checking a file for
858    changes and send alert or execute an action. Monit will register
859    the size of the file at startup and monitor the file for
860    changes. One usage of this statement is to conduct security
861    checks, for instance:</P>
862    <PRE>
863     check file su with path /bin/su
864      if size was changed then exec &quot;/sbin/ifconfig eth0 down&quot;</PRE>
865    <P>which will ``cut the cable'' and stop a possible intruder from
866    further system compromitation.</P>
867    <P>This test is just one of many you may use to increase the systems
868    security awareness. If you plan to use monit to raise the
869    security level for your system we recommend that you use this
870    test in combination with other supported tests like checksum,
871    timestamp, and so on.</P>
872    <P>The second size version may be useful in different contexts. It
873    can, for instance, be used to test if a certain file size was
874    exceeded and then alert you or monit may execute a certain action
875    specified by you. An example is to use this statement to rotate
876    log files after they have reached a certain size or to check that
877    database files does not grow above a specified threshold.</P>
878    <P>To rotate a log file:</P>
879    <PRE>
880     check file myapp.log with path /var/log/myapp.log
881      if size &gt; 50 MB then
882       exec &quot;/usr/local/bin/rotate /var/log/myapp.log myapp&quot;</PRE>
883    <P>where /usr/local/bin/rotate may be a simple script, such as:</P>
884    <PRE>
885     #/bin/bash
886     /bin/mv $1 $1.`date +%y-%m-%d`
887     /usr/bin/pkill -HUP $2</PRE>
888    <P>Or you may use this statement to trigger the <CODE>logrotate(8)</CODE>
889    program, to do an ``emergency'' rotate.</P>
890    <P>Or to send alerts if a file becomes a bottleneck if it grows
891    behind a fixed size because of limits in a database engine:</P>
892    <PRE>
893     check file mydb with path /data/mydatabase.db
894      if size &gt; 1 GB then alert</PRE>
895    <P>This is a more restrictive form of the first example where the
896    size is explicitly defined (Note that this is system dependent):</P>
897  <PRE>  <PRE>
898   [HOST hostname] PORT number   check file su with path /bin/su
899           [TYPE {TCP|UDP|TCPSSL [SSLAUTO|SSLV2|SSLV3|TLSV1]    if size != 95564 then exec &quot;/sbin/ifconfig eth0 down&quot;</PRE>
900                                 [CERTMD5 md5sum]  <P>
901                 }]  <HR>
902           [PROTO(COL) {name} [REQUEST {&quot;/path&quot;}]]</PRE>  <H1><A NAME="connection testing">CONNECTION TESTING</A></H1>
903    <P>Monit is able to perfom connection testing via networked ports or
904    via unix sockets.</P>
905    <P>If a service listens on one or more sockets, monit can connect to
906    the port (using either tcp or udp) and verify that the service
907    will accept a connection and that it is possible to write and
908    read from the socket. If a connection is not accepted or if there
909    is a problem with socket read/write, monit will assume that
910    something is wrong and execute a specified action. If monit is
911    compiled with openssl, ssl based network services can also be
912    tested.</P>
913    <P>The full syntax for the statement used for connection testing is
914    as follows (keywords are in capital and optional statements in
915    [brackets]),</P>
916    <DL>
917    <DT><STRONG><A NAME="item_IF_FAILED_%5Bhost%5D_port_%5Btype%5D_%5Bprotocol%5">IF FAILED [host] port [type] [protocol] [timeout]
918          THEN action</A></STRONG><BR>
919    <DD>
920    </DL>
921  <P>or for unix sockets,</P>  <P>or for unix sockets,</P>
922    <DL>
923    <DT><STRONG><A NAME="item_IF_FAILED_%5Bunixsocket%5D_%5Btype%5D_%5Bprotocol%">IF FAILED [unixsocket] [type] [protocol] [timeout]
924          THEN action</A></STRONG><BR>
925    <DD>
926    </DL>
927    <P><STRONG>host</STRONG> optionally specify the host to connect to. If the host is
928    not given, localhost is assumed. Although <EM>host</EM> is intended for
929    testing name based virtual host in a HTTP server running on
930    localhost, it does allow the connection statement to be used to
931    test a server running on another machine. This may be very
932    useful; For instance if you use Apache httpd as a front-end and
933    an application-server as the back-end running on another machine,
934    this statement may be used to test that the back-end server is
935    running and if not raise an alert.</P>
936    <P><STRONG>port</STRONG> is the port number to connect to</P>
937    <P><STRONG>unixsocket</STRONG> specifies the path to a unix socket. Servers based
938    on unix sockets, always runs on the local machine and does not
939    use a port.</P>
940    <P><STRONG>type</STRONG> optionally specify the socket type monit should use when
941    trying to connect to the port. The different socket types are;
942    TCP, UDP or TCPSSL, where TCP is a regular stream based socket,
943    UDP a datagram socket and TCPSSL specify that monit should use a
944    TCP socket with SSL when connecting to the server. The default
945    socket type is TCP. If TCPSSL is used you may optionally specify
946    the SSL/TLS protocol to be used and the md5 sum of the server's
947    certificate. The TCPSSL options are:</P>
948    <PRE>
949     TCPSSL [SSLAUTO|SSLV2|SSLV3|TLSV1] [CERTMD5 md5sum]</PRE>
950    <P><STRONG>proto(col)</STRONG> optionally specify the protocol monit should speak
951    when a connection is established. At the moment monit knows how
952    to speak <EM>HTTP</EM>, <EM>SMTP</EM>, <EM>FTP</EM>, <EM>POP</EM>, <EM>IMAP</EM>, <EM>NNTP</EM>,
953    <EM>SSH</EM>, <EM>DWP</EM>, <EM>LDAP2</EM>, <EM>LDAP3</EM> and <EM>RDATE</EM> and if you have
954    compiled monit with ssl support, monit can also speak <EM>HTTPS</EM>,
955    <EM>FTPS</EM>, <EM>POPS</EM> and <EM>IMAPS</EM>. If the server's protocol is not
956    found in this list, simply do not specify the protocol and monit
957    will utilize a default test, including testing if it is possible
958    to read and write to the port. This default test is in many cases
959    more than good enough to deduce if the server behind the port is
960    up or not. The protocol statement is:</P>
961    <PRE>
962     [PROTO(COL) {name} [REQUEST {&quot;/path&quot;}]]</PRE>
963    <P>As you can see, you may specify a request after the protocol, at
964    the moment only the HTTP protocol supports the request option.
965    See also below.</P>
966    <P><STRONG>timeout</STRONG> optionally specifies the connect and read timeout for
967    the connection. If monit cannot connect to the server within this
968    time it will assume that the connection failed and execute the
969    specified action. The default timeout is 5 seconds. The timeout
970    statement is:</P>
971    <PRE>
972      [with TIMEOUT x SECONDS]</PRE>
973    <P><STRONG>action</STRONG> is a choice of ``ALERT'', ``RESTART'', ``STOP'', ``EXEC'' or
974    ``UNMONITOR'':</P>
975    <UL>
976    <LI>
977    ALERT sends the user a connection alert.
978    <P></P>
979    <LI>
980    RESTART restarts the service.
981    <P></P>
982    <LI>
983    STOP stops the service. If monit stops a service it will
984    not be checked by monit anymore nor restarted again later. You
985    must explicit start it again from the web interface or from the
986    console, like: 'monit start myfile' or 'monit monitor myfile'
987    if you want the monit daemon to monitor the service again.
988    <P></P>
989    <LI>
990    EXEC may be used to execute an arbitrary program. If you choose
991    this action you must state the program to be executed. For
992    instance; exec ``/etc/init.d/network restart''
993    <P></P>
994    <LI>
995    UNMONITOR will disable monitoring of the service - it will not be
996    checked by monit anymore nor restarted again later. The chain of
997    all services which depends on this service will be unmonitored
998    before this service monitoring will be stopped. You can enable
999    monitoring again either via console 'monitor' command, via web
1000    interface or use 'start' command, which will enable the
1001    monitoring too.
1002    <P></P></UL>
1003    <P>
1004    <H4><A NAME="examples">Examples</A></H4>
1005    <P>To check a port connection and receive an alert if monit cannot
1006    connect to the port, use the following statement:</P>
1007  <PRE>  <PRE>
1008   UNIX(SOCKET) path [TYPE {TCP|UDP}] [PROTO(COL) {name}    if failed port 80 then alert</PRE>
   [REQUEST {&quot;/path&quot;}]]</PRE>  
 <P>To have monit check a port connection use the following statement:</P>  
 <PRE>  
   port 80</PRE>  
1009  <P>In this case the machine in question is assumed to be  <P>In this case the machine in question is assumed to be
1010  <EM>localhost</EM> and monit will issue a tcp connection to localhost  <EM>localhost</EM> and monit will conduct a tcp connection to localhost
1011  at port 80. Monit will use tcp by default, if you want to connect  at port 80. Monit will use tcp by default, if you want to connect
1012  with udp, you can specify this after the port-statement;</P>  with udp, you can specify this after the port-statement;</P>
1013  <PRE>  <PRE>
1014   port 53 use type udp ('use' is a noise keyword)</PRE>   if failed port 53 type udp then alert</PRE>
1015  <P>The <EM>TCPSSL</EM> statement accepts optionally the md5 sum of the  <P>Monit will stop trying to connect to the port after 5 seconds and
1016  server's certificate.  The md5 sum is matched against the one  assume that the server behind the port is down. You may increase
1017  delivered by the server.  In case they do not match the  or decrease the connect timeout by explicit add a connection
1018  connection test fails.  In case the ssl version independant  timeout. In the following example the timeout is increased to 15
1019  handshake is not working properly you can force a specific ssl  seconds and if monit cannot connect to the server within 15
1020  version, too.</P>  seconds the test will fail and an alert message is sent.</P>
1021  <P>In case a server is listening to a unix socket called  <PRE>
1022  /var/run/mysocket, the following statement can be used:</P>    if failed port 80 with timeout 15 seconds then alert</PRE>
1023  <PRE>  <P>In case a server is listening to a unix socket the following
1024   unix /var/run/mysocket</PRE>  statement can be used:</P>
1025    <PRE>
1026     if failed unixsocket /var/run/mysocket then alert</PRE>
1027    <P>A unix socket is used by some servers to conduct communication on
1028    localhost only. An open unix socket is specified by a path and in
1029    the example above the path, /var/run/mysocket, specifies a unix
1030    socket.</P>
1031  <P>If your machine answers for several virtual hosts you can prefix  <P>If your machine answers for several virtual hosts you can prefix
1032  the port statement with a host-statement like so:</P>  the port statement with a host-statement like so:</P>
1033  <PRE>  <PRE>
1034   host www.sol.no     port 80   if failed host www.sol.no port 80 then alert
1035   host shop.sol.no    port 443   if failed host 80.69.226.133 port 443 then alert
1036   host kvasir.sol.no  port 80   if failed host kvasir.sol.no port 80 then alert</PRE>
  host 10.2.3.4       port 80</PRE>  
1037  <P>And as mentioned above, if you do not specify a host-statement,  <P>And as mentioned above, if you do not specify a host-statement,
1038  <EM>localhost</EM> is assumed.</P>  <EM>localhost</EM> is assumed.</P>
1039  <P>Finally, monit also knows how to speak some of the more popular  <P>Monit also knows how to speak some of the more popular Internet
1040  Internet protocols. So, besides testing for connections, monit  protocols. So, besides testing for connections, monit can also
1041  can also speak with the server in question to verify that the  speak with the server in question to verify that the server
1042  server works. For example, the following is used to test a http  works. For example, the following is used to test a http server:</P>
 server:  
 </P>  
1043  <PRE>  <PRE>
1044     if failed host www.tildeslash.com port 80 protocol http
1045   host www.tildeslash.com port 80 protocol http</PRE>   then restart</PRE>
 <P>At the moment monit knows how to speak <EM>HTTP</EM>, <EM>SMTP</EM>, <EM>FTP</EM>,  
 <EM>POP</EM>, <EM>IMAP</EM>, <EM>NNTP</EM>, <EM>SSH</EM>, <EM>DWP</EM>, <EM>LDAP2</EM> and <EM>LDAP3</EM>.  
 If you have compiled monit with ssl support, monit can also speak  
 <EM>HTTPS</EM>, <EM>FTPS</EM>, <EM>POPS</EM> and <EM>IMAPS</EM>.</P>  
1046  <P>Some protocols also support a request statement. This statement  <P>Some protocols also support a request statement. This statement
1047  can be used to ask the server for a special document entity.</P>  can be used to ask the server for a special document entity.</P>
1048  <P>Currently <STRONG>only</STRONG> the <EM>HTTP</EM> protocol module supports the  <P>Currently <STRONG>only</STRONG> the <EM>HTTP</EM> protocol module supports the
1049  request statement, such as:</P>  request statement, such as:</P>
1050  <PRE>  <PRE>
1051   host www.myhost.com port 80 protocol http   if failed host www.myhost.com port 80 protocol http
1052     request &quot;/data/show.php?a=b&amp;c=d&quot;</PRE>     request &quot;/data/show.php?a=b&amp;c=d&quot;
1053  <P>The request should contain an URI string specifying a document   then restart</PRE>
1054  from the http server. The string will be url encoded by monit  <P>The request must contain an URI string specifying a document from
1055  before it sends the request to the http server, so it's okay to  the http server. The string will be url encoded by monit before
1056  use url unsafe characters in the request.</P>  it sends the request to the http server, so it's okay to use url
1057    unsafe characters in the request.</P>
1058  <P>If the request statement isn't specified, the default web server  <P>If the request statement isn't specified, the default web server
1059  page will be requested.</P>  page will be requested.</P>
1060  <P>It is of course possible to mix networked ports and unix sockets  <P>The <EM>TCPSSL</EM> statement accepts optionally the md5 sum of the
1061  checks for a service.</P>  server's certificate. The md5 sum is matched against the one
1062    delivered by the server. In case they do not match the connection
1063    test fails.  In case the ssl version independant handshake is not
1064    working properly you can force a specific ssl version, as we
1065    demonstrate in this example:</P>
1066    <PRE>
1067     if failed host shop.sol.no port 443
1068       type TCPSSL SSLV3
1069       CERTMD5 94A07F97ADFEDEDD16F053EEE6351AB1
1070       protocol http
1071     then restart</PRE>
1072    <P>Finally, it is of course possible to mix networked ports and unix
1073    sockets checks for a service.</P>
1074  <P>See also the example section below.</P>  <P>See also the example section below.</P>
1075  <P>  <P>
1076  <HR>  <HR>
1077    <H1><A NAME="space testing">SPACE TESTING</A></H1>
1078    <P>Monit supports test of devices/filesystems. You can check for
1079    space usage.</P>
1080    <P>Monit will check total usage =&gt; if you need to check the usage
1081    for non-superuser available space, you must set the watermark
1082    appropriately (total space minus superuser reserved blocks).</P>
1083    <P>You can obtain (and set) live filesystem actual superuser reserved
1084    blocks limit, uid and group for example by tune2fs utility on
1085    linux. Linux has 5% blocks reserved by default. To list
1086    informations:</P>
1087    <PRE>
1088     [root@berry monit]# tune2fs -l /dev/hda1| grep &quot;Reserved block&quot;
1089     Reserved block count:     5219
1090     Reserved blocks uid:      0 (user root)
1091     Reserved blocks gid:      0 (group root)</PRE>
1092    <P>Solaris has by default 10% blocks reserved. You can use tunefs
1093    on solaris to change it on live filesystem.</P>
1094    <P>The full syntax for the space testing statement is:</P>
1095    <DL>
1096    <DT><STRONG><A NAME="item_IF_SPACE_operator_value_unit_THEN_action">IF SPACE operator value unit THEN action</A></STRONG><BR>
1097    <DD>
1098    </DL>
1099    <P><EM>operator</EM> is a choice of ``&lt;'',``&gt;'',``!='',``=='' in c notation, ``gt'',
1100    ``lt'', ``eq'', ``ne'' in shell sh notation and ``greater'', ``less'',
1101    ``equal'', ``notequal'' in human readable form (if not specified,
1102    default is EQUAL).</P>
1103    <P><EM>unit</EM> is a choice of ``B'',``KB'',``MB'',``GB'', ``%'' or long
1104    alternatives ``byte'', ``kilobyte'', ``megabyte'', ``gigabyte'',
1105    ``percent''.</P>
1106    <P><EM>action</EM> is a choice of ``ALERT'', ``RESTART'', ``STOP'', ``EXEC'' or
1107    ``UNMONITOR'':</P>
1108    <UL>
1109    <LI>
1110    ALERT sends the user a resource alert.
1111    <P></P>
1112    <LI>
1113    RESTART restarts the service.
1114    <P></P>
1115    <LI>
1116    STOP stops the service. If monit stops a service it will
1117    not be checked by monit anymore nor restarted again later. You
1118    must explicit start it again from the web interface or from the
1119    console, like: 'monit start datafs' or 'monit monitor datafs'
1120    if you want the monit daemon to monitor the service again.
1121    <P></P>
1122    <LI>
1123    EXEC may be used to execute an arbitrary program. If you choose
1124    this action you must state the program to be executed.
1125    <P></P>
1126    <LI>
1127    UNMONITOR will disable monitoring of the service - it will not be
1128    checked by monit anymore nor restarted again later. The chain of
1129    all services which depends on this service will be unmonitored
1130    before this service monitoring will be stopped. You can enable
1131    monitoring again either via console 'monitor' command, via web
1132    interface or use 'start' command, which will enable the
1133    monitoring too.
1134    <P></P></UL>
1135    <P>
1136    <HR>
1137    <H1><A NAME="inode testing">INODE TESTING</A></H1>
1138    <P>Monit supports test of devices and filesystems. You can check for
1139    inodes usage if supported by the filesystem.</P>
1140    <P>In the case that the device becomes unavailable, monit will
1141    call start/stop methods whenever defined if it is running in
1142    active mode. In the case that it is running in passive mode or
1143    start/stop methods were not defined, it will just send failure
1144    alert.</P>
1145    <P>Full syntax of inode testing statement:</P>
1146    <DL>
1147    <DT><STRONG><A NAME="item_INODE">IF <CODE>INODE(S)</CODE> operator value [unit] THEN action</A></STRONG><BR>
1148    <DD>
1149    </DL>
1150    <P><EM>operator</EM> is a choice of ``&lt;'',``&gt;'',``!='',``=='' in c notation, ``gt'',
1151    ``lt'', ``eq'', ``ne'' in shell sh notation and ``greater'', ``less'',
1152    ``equal'', ``notequal'' in human readable form (if not specified,
1153    default is EQUAL).</P>
1154    <P><EM>unit</EM> is optional. If not specified, the value is an absolute
1155    count of inodes. You can use the ``%'' character or the longer
1156    alternative ``percent'' as a unit.</P>
1157    <P><EM>action</EM> is a choice of ``ALERT'', ``RESTART'', ``STOP'', ``EXEC'' or
1158    ``UNMONITOR'':</P>
1159    <UL>
1160    <LI>
1161    ALERT sends the user a resource alert.
1162    <P></P>
1163    <LI>
1164    RESTART restarts the service.
1165    <P></P>
1166    <LI>
1167    STOP stops the service. If monit stops a service it will
1168    not be checked by monit anymore nor restarted again later. You
1169    must explicit start it again from the web interface or from the
1170    console, like: 'monit start datafs' or 'monit monitor datafs'
1171    if you want the monit daemon to monitor the service again.
1172    <P></P>
1173    <LI>
1174    EXEC may be used to execute an arbitrary program. If you choose
1175    this action you must state the program to be executed.
1176    <P></P>
1177    <LI>
1178    UNMONITOR will disable monitoring of the service - it will not be
1179    checked by monit anymore nor restarted again later. The chain of
1180    all services which depends on this service will be unmonitored
1181    before this service monitoring will be stopped. You can enable
1182    monitoring again either via console 'monitor' command, via web
1183    interface or use 'start' command, which will enable the
1184    monitoring too.
1185    <P></P></UL>
1186    <P>
1187    <HR>
1188    <H1><A NAME="permission testing">PERMISSION TESTING</A></H1>
1189    <P>Monit can watch file, directory or device permission.</P>
1190    <P>Full syntax is:</P>
1191    <DL>
1192    <DT><STRONG><A NAME="item_PERM">IF FAILED <CODE>PERM(ISSION)</CODE> octalnumber THEN action</A></STRONG><BR>
1193    <DD>
1194    </DL>
1195    <P><EM>octalnumber</EM> defines appropriate file, directory or device
1196    permissions.</P>
1197    <P><EM>action</EM> is a choice of ``ALERT'', ``RESTART'', ``STOP'', ``EXEC'' or
1198    ``UNMONITOR'':</P>
1199    <UL>
1200    <LI>
1201    ALERT sends the user a permission alert.
1202    <P></P>
1203    <LI>
1204    RESTART restarts the service.
1205    <P></P>
1206    <LI>
1207    STOP stops the service. If monit stops a service it will
1208    not be checked by monit anymore nor restarted again later. You
1209    must explicit start it again from the web interface or from the
1210    console, like: 'monit start myfile' or 'monit monitor myfile'
1211    if you want the monit daemon to monitor the service again.
1212    <P></P>
1213    <LI>
1214    EXEC may be used to execute an arbitrary program. If you choose
1215    this action you must state the program to be executed. For
1216    instance; exec ``/sbin/ifconfig eth0 down''
1217    <P></P>
1218    <LI>
1219    UNMONITOR will disable monitoring of the service - it will not be
1220    checked by monit anymore nor restarted again later. The chain of
1221    all services which depends on this service will be unmonitored
1222    before this service monitoring will be stopped. You can enable
1223    monitoring again either via console 'monitor' command, via web
1224    interface or use 'start' command, which will enable the
1225    monitoring too.
1226    <P></P></UL>
1227    <P>The web interface will show a permission warning in the case that
1228    it failed.</P>
1229    <P>We recommend to use UNMONITOR action in the permission statement. The
1230    rationale for this feature is security and that monit does not
1231    start a possible cracked program or script. Example:</P>
1232    <PRE>
1233     check file myfile with path &quot;/path/to/myfile&quot;
1234       if failed permission 700 then unmonitor</PRE>
1235    <P>It will just stop service monitoring. In the case that some other
1236    service depends on myfile service, unmonitor event will be send
1237    to it and all its dependants as well.</P>
1238    <P>
1239    <HR>
1240    <H1><A NAME="uid testing">UID TESTING</A></H1>
1241    <P>Monit can watch file, directory or device owner user id.</P>
1242    <P>Full syntax is:</P>
1243    <DL>
1244    <DT><STRONG><A NAME="item_IF_FAILED_UID_user_THEN_action">IF FAILED UID user THEN action</A></STRONG><BR>
1245    <DD>
1246    </DL>
1247    <P><EM>user</EM> defines appropriate file, directory or device
1248    owner user id either in numeric or string form.</P>
1249    <P><EM>action</EM> is a choice of ``ALERT'', ``RESTART'', ``STOP'', ``EXEC'' or
1250    ``UNMONITOR'':</P>
1251    <UL>
1252    <LI>
1253    ALERT sends the user a uid alert.
1254    <P></P>
1255    <LI>
1256    RESTART restarts the service.
1257    <P></P>
1258    <LI>
1259    STOP stops the service. If monit stops a service it will
1260    not be checked by monit anymore nor restarted again later. You
1261    must explicit start it again from the web interface or from the
1262    console, like: 'monit start myfile' or 'monit monitor myfile'
1263    if you want the monit daemon to monitor the service again.
1264    <P></P>
1265    <LI>
1266    EXEC may be used to execute an arbitrary program. If you choose
1267    this action you must state the program to be executed. For
1268    instance; exec ``/sbin/ifconfig eth0 down''
1269    <P></P>
1270    <LI>
1271    UNMONITOR will disable monitoring of the service - it will not be
1272    checked by monit anymore nor restarted again later. The chain of
1273    all services which depends on this service will be unmonitored
1274    before this service monitoring will be stopped. You can enable
1275    monitoring again either via console 'monitor' command, via web
1276    interface or use 'start' command, which will enable the
1277    monitoring too.
1278    <P></P></UL>
1279    <P>The web interface will show a uid warning in the case that it
1280    failed.</P>
1281    <P>We recommend to use UNMONITOR action in the uid statement. The
1282    rationale for this feature is security and that monit does not
1283    start a possible cracked program or script. Example:</P>
1284    <PRE>
1285     check file myfile with path &quot;/path/to/myfile&quot;
1286       if failed uid root then unmonitor</PRE>
1287    <P>It will just stop service monitoring. In the case that some other
1288    service depends on myfile service, unmonitor event will be send
1289    to it and all its dependants as well.</P>
1290    <P>
1291    <HR>
1292    <H1><A NAME="gid testing">GID TESTING</A></H1>
1293    <P>Monit can watch file, directory or device owner group id.</P>
1294    <P>Full syntax is:</P>
1295    <DL>
1296    <DT><STRONG><A NAME="item_IF_FAILED_GID_user_THEN_action">IF FAILED GID user THEN action</A></STRONG><BR>
1297    <DD>
1298    </DL>
1299    <P><EM>user</EM> defines appropriate file, directory or device
1300    owner group id either in numeric or string form.</P>
1301    <P><EM>action</EM> is a choice of ``ALERT'', ``RESTART'', ``STOP'', ``EXEC'' or
1302    ``UNMONITOR'':</P>
1303    <UL>
1304    <LI>
1305    ALERT sends the user a gid alert.
1306    <P></P>
1307    <LI>
1308    RESTART restarts the service.
1309    <P></P>
1310    <LI>
1311    STOP stops the service. If monit stops a service it will
1312    not be checked by monit anymore nor restarted again later. You
1313    must explicit start it again from the web interface or from the
1314    console, like: 'monit start myfile' or 'monit monitor myfile'
1315    if you want the monit daemon to monitor the service again.
1316    <P></P>
1317    <LI>
1318    EXEC may be used to execute an arbitrary program. If you choose
1319    this action you must state the program to be executed. For
1320    instance; exec ``/sbin/ifconfig eth0 down''
1321    <P></P>
1322    <LI>
1323    UNMONITOR will disable monitoring of the service - it will not be
1324    checked by monit anymore nor restarted again later. The chain of
1325    all services which depends on this service will be unmonitored
1326    before this service monitoring will be stopped. You can enable
1327    monitoring again either via console 'monitor' command, via web
1328    interface or use 'start' command, which will enable the
1329    monitoring too.
1330    <P></P></UL>
1331    <P>The web interface will show a gid warning in the case that it
1332    failed.</P>
1333    <P>We recommend to use UNMONITOR action in the uid statement. The
1334    rationale for this feature is security and that monit does not
1335    start a possible cracked program or script. Example:</P>
1336    <PRE>
1337     check file myfile with path &quot;/path/to/myfile&quot;
1338       if failed gid root then unmonitor</PRE>
1339    <P>It will just stop service monitoring. In the case that some other
1340    service depends on myfile service, unmonitor event will be send
1341    to it and all its dependants as well.</P>
1342    <P>
1343    <HR>
1344  <H1><A NAME="monit httpd">MONIT HTTPD</A></H1>  <H1><A NAME="monit httpd">MONIT HTTPD</A></H1>
1345  <P>If specified in the control file, monit will start a monit daemon  <P>If specified in the control file, monit will start a monit daemon
1346  with http support. From a Browser you can then start and stop  with http support. From a Browser you can then start and stop
1347  programs as well as view the status of each program. Also, if  services as well as view the status of each service. Also, if
1348  monit logs to its own file, you can view the content of this  monit logs to its own file, you can view the content of this
1349  logfile in a Browser.</P>  logfile in a Browser.</P>
1350  <P>The control file statement for starting a monit daemon with http  <P>The control file statement for starting a monit daemon with http
1351  support is a global set-statement:</P>  support is a global set-statement:</P>
1352  <PRE>  <DL>
1353    set httpd port 2812</PRE>  <DT><STRONG><A NAME="item_set_httpd_port_2812">set httpd port 2812</A></STRONG><BR>
1354    <DD>
1355    </DL>
1356  <P>And you can use this URL, <EM><A HREF="http://localhost:2812/">http://localhost:2812/</A></EM>, to access  <P>And you can use this URL, <EM><A HREF="http://localhost:2812/">http://localhost:2812/</A></EM>, to access
1357  the daemon from a browser.</P>  the daemon from a browser.</P>
1358  <P>The port number, in this case 2812, can be any number that you  <P>The port number, in this case 2812, can be any number that you
# Line 660  are allowed to bind to.</P> Line 1361  are allowed to bind to.</P>
1361  start the httpd server with ssl support, using the following  start the httpd server with ssl support, using the following
1362  expression:</P>  expression:</P>
1363  <PRE>  <PRE>
1364    set httpd port 2812   set httpd port 2812
1365          ssl enable       ssl enable
1366          pemfile /etc/certs/monit.pem</PRE>       pemfile /etc/certs/monit.pem</PRE>
1367  <P>And you can use this URL, <EM><A HREF="https://localhost:2812/">https://localhost:2812/</A></EM>, to access  <P>And you can use this URL, <EM><A HREF="https://localhost:2812/">https://localhost:2812/</A></EM>, to access
1368  the monit web server over an ssl encrypted connection.</P>  the monit web server over an ssl encrypted connection.</P>
1369  <P>The pemfile, in the example above, holds the private key and the  <P>The pemfile, in the example above, holds the private key and the
# Line 674  please consult README.ssl</P> Line 1375  please consult README.ssl</P>
1375  use the CLIENTPEMFILE statement.  In that case a connecting  use the CLIENTPEMFILE statement.  In that case a connecting
1376  client has to have a sufficient key and certificate in order to  client has to have a sufficient key and certificate in order to
1377  connect.  This file also needs to have all necessary CA  connect.  This file also needs to have all necessary CA
1378  certificates. A configuration could look like:  certificates. A configuration could look like:</P>
 </P>  
1379  <PRE>  <PRE>
1380     set httpd port 2812
1381    set httpd port 2812       ssl enable
1382          ssl enable       pemfile /etc/certs/monit.pem
1383          pemfile /etc/certs/monit.pem       clientpemfile /etc/certs/monit-client.pem</PRE>
         clientpemfile /etc/certs/monit-client.pem</PRE>  
1384  <P>By default self signed certificates are not allowed.  In case you need  <P>By default self signed certificates are not allowed.  In case you need
1385  to use them it has to be allowed explicitly with the  to use them it has to be allowed explicitly with the
1386  ALLOWSELFCERTIFICATION statement.</P>  ALLOWSELFCERTIFICATION statement.</P>
# Line 715  daemon.</P> Line 1414  daemon.</P>
1414  be able to use the following console commands.</P>  be able to use the following console commands.</P>
1415  <PRE>  <PRE>
1416   'monit stop'   'monit stop'
1417   'monit start program'   'monit start service'
1418   'monit stop program'   'monit stop service'
1419   'monit restart program'   'monit restart service'
1420     'monit monitor service'
1421     'monit unmonitor service'
1422   'monit -g groupname start'   'monit -g groupname start'
1423   'monit -g groupname stop'   'monit -g groupname stop'
1424   'monit -g groupname restart'</PRE>   'monit -g groupname restart'
1425     'monit -g groupname monitor'
1426     'monit -g groupname unmonitor'</PRE>
1427  <P>If a monit daemon is running in the background we will ask the  <P>If a monit daemon is running in the background we will ask the
1428  deamon (via the HTTP protocol) to execute the above commands.  deamon (via the HTTP protocol) to execute the above commands.
1429  That is, the daemon is requested to start and stop the programs.  That is, the daemon is requested to start and stop the services.
1430  This ensures that a daemon will not restart a program that you  This ensures that a daemon will not restart a service that you
1431  requested to stop and that (any) timeout lock will be removed  requested to stop and that (any) timeout lock will be removed
1432  from a program when you start it.</P>  from a service when you start it.</P>
1433  <P>  <P>
1434  <H2><A NAME="monit httpd authentication">Monit HTTPD Authentication</A></H2>  <H2><A NAME="monit httpd authentication">Monit HTTPD Authentication</A></H2>
1435  <P>monit supports two types of autenthication schemas for connecting  <P>monit supports two types of autenthication schemas for connecting
# Line 792  password is written in clear-text. (Use Line 1495  password is written in clear-text. (Use
1495  complain and exit if the control file is readable by others.</P>  complain and exit if the control file is readable by others.</P>
1496  <P>  <P>
1497  <HR>  <HR>
 <H1><A NAME="md5 checksum">MD5 CHECKSUM</A></H1>  
 <P>If specified in the control file, monit will compute a md5  
 checksum for programs. The checksum is used to verify that a  
 program does not change. If a program was changed, monit will  
 send an (optional) alert notification, log an alert message and  
 not check the process anymore. The web interface will also show a  
 checksum warning.</P>  
 <P>The rationale for this feature is security and that monit does  
 not start a possible cracked program or script.</P>  
 <P>The full syntax for the checksum-statement is as follows:  
 (keywords are in capital)</P>  
 <PRE>  
  CHECKSUM [file [EXPECT checksum] ]+</PRE>  
 <P>A legal (but verbose) way to write a checksum statement for a  
 process entry in the control file is:</P>  
 <PRE>  
  checksum the /usr/bin/httpd program</PRE>  
 <P>The shorthand version is just:</P>  
 <PRE>  
  checksum /usr/bin/httpd</PRE>  
 <P>Several files can be used in a checksum statement:</P>  
 <PRE>  
  checksum /usr/apache/bin/httpd /usr/apache-ssl/bin/httpsd</PRE>  
 <P>or on a line by itself:</P>  
 <PRE>  
  checksum /usr/apache/bin/httpd  
  checksum /usr/apache-ssl/bin/httpsd</PRE>  
 <P>You can add as many 'checksum file' statements as you want. Like  
 described above, if the checksum for a file changes, monit will  
 log a warning, issue an alert message and not check the  
 associated process anymore.</P>  
 <P>The <EM>expect</EM> statement is optional and used to specify a md5  
 string monit should expect when testing a file's checksum. If  
 this statement is used monit will not compute an initial checksum  
 for the file, as in the examples above, but instead use the  
 string you submit. For example:</P>  
 <PRE>  
  checksum /usr/bin/httpd expect 8f7f419955cefa0b33a2ba316cba3659</PRE>  
 <P>or verbose style;</P>  
 <PRE>  
  checksum /usr/bin/httpd and  
    expect the sum 4e5309d1956f003bcdff168748bea647</PRE>  
 <P>You can, for example, use the GNU utility <EM>md5sum</EM> to create a  
 checksum string for a file and then use this string in the  
 expect-statement.</P>  
 <P>  
 <HR>  
1498  <H1><A NAME="dependency checking">DEPENDENCY CHECKING</A></H1>  <H1><A NAME="dependency checking">DEPENDENCY CHECKING</A></H1>
1499  <P>If specified in the control file, monit can do dependency  <P>If specified in the control file, monit can do dependency
1500  checking before starting or stopping processes. The syntax for  checking before starting, stopping, monitoring or unmonitoring
1501  the depend statement is simply:</P>  services. The syntax for the depend statement is simply:</P>
1502  <PRE>  <DL>
1503   DEPENDS [process]+</PRE>  <DT><STRONG><A NAME="item_DEPENDS_on_service%5B%2C_service_%5B%2C%2E%2E%2E%5">DEPENDS on service[, service [,...]]</A></STRONG><BR>
1504  <P>Where <STRONG>process</STRONG> is a process entry name, for instance <STRONG>apache</STRONG>.  <DD>
1505  You may add more than one process name or use more than one  </DL>
1506  depend statement in an entry.</P>  <P>Where <STRONG>service</STRONG> is a service entry name, for instance <STRONG>apache</STRONG>
1507  <P>Processes specified in a <EM>depends</EM> statement will be checked  or <STRONG>datafs</STRONG>.</P>
1508  during stop/start operations. If a process is stopped it will  <P>You may add more than one service name of any type (device,
1509  stop any processes that depends on itself. Likewise, if a process  directory, file or process) or use more than one depend statement
1510  is started, it will first stop any processes that depends on  in an entry.</P>
1511  itself and after it is started, start all depending processes  <P>Services specified in a <EM>depends</EM> statement will be checked
1512  again.</P>  during stop/start/monitor/unmonitor operations. If a service
1513    is stopped or unmonitored it will stop/unmonitor any services
1514    that depends on itself. Likewise, if a service is started, it
1515    will first stop any services that depends on itself and after
1516    it is started, start all depending services again. If the
1517    service is to be monitored (enable monitoring), all services
1518    which this service depends on will be monitored before enabling
1519    monitoring of this service.</P>
1520  <P>Consider the following common server setup:</P>  <P>Consider the following common server setup:</P>
1521  <PRE>  <PRE>
1522     (a) WEB-SERVER -&gt; (b) APPLICATION-SERVER -&gt; (c) DATABASE</PRE>    WEB-SERVER -&gt; APPLICATION-SERVER -&gt; DATABASE -&gt; FILESYSTEM
1523          (a)               (b)             (c)          (d)</PRE>
1524  <P>You can set dependencies so that the web-server depends on the  <P>You can set dependencies so that the web-server depends on the
1525  application server to run before the web-server starts and the  application server to run before the web-server starts and the
1526  application server depends on the database server. See also the  application server depends on the database server and the
1527  example section below for examples using the depend statement.</P>  database depends on filesystem to be mounted before it starts.
1528    See also the example section below for examples using the depend
1529    statement.</P>
1530  <P>Here we describe how monit will function with the above  <P>Here we describe how monit will function with the above
1531  dependencies:</P>  dependencies:</P>
1532  <DL>  <DL>
1533  <DT><STRONG><A NAME="item_If_no_servers_are_running">If no servers are running</A></STRONG><BR>  <DT><STRONG><A NAME="item_If_no_servers_are_running">If no servers are running</A></STRONG><BR>
1534  <DD>  <DD>
1535  monit will start the servers in the following order: <EM>c</EM>, <EM>b</EM>,  monit will start the servers in the following order: <EM>d</EM>, <EM>c</EM>,
1536  <EM>a</EM>  <EM>b</EM>, <EM>a</EM>
1537  <P></P>  <P></P>
1538  <DT><STRONG><A NAME="item_If_all_servers_are_running">If all servers are running</A></STRONG><BR>  <DT><STRONG><A NAME="item_If_all_servers_are_running">If all servers are running</A></STRONG><BR>
1539  <DD>  <DD>
1540  When you run 'monit stop' this is the stop order: <EM>a</EM>, <EM>b</EM>,  When you run 'monit stop' this is the stop order: <EM>a</EM>, <EM>b</EM>,
1541  <EM>c</EM>. If you run 'monit stop c' then <EM>a</EM> and <EM>b</EM> are stopped  <EM>c</EM>, <EM>d</EM>. If you run 'monit stop d' then <EM>a</EM>, <EM>b</EM> and <EM>c</EM>
1542  because they depend on <EM>c</EM> and finally <EM>c</EM> is stopped.  are stopped because they depend on <EM>d</EM> and finally <EM>d</EM> is
1543    stopped.
1544  <P></P>  <P></P>
1545  <DT><STRONG><A NAME="item_If_a_does_not_run">If <EM>a</EM> does not run</A></STRONG><BR>  <DT><STRONG><A NAME="item_If_a_does_not_run">If <EM>a</EM> does not run</A></STRONG><BR>
1546  <DD>  <DD>
# Line 889  finally start <EM>a</EM> again. Line 1556  finally start <EM>a</EM> again.
1556  When monit runs it will first stop <EM>a</EM> and <EM>b</EM> then start <EM>c</EM>  When monit runs it will first stop <EM>a</EM> and <EM>b</EM> then start <EM>c</EM>
1557  and finally start <EM>b</EM> then <EM>a</EM>.  and finally start <EM>b</EM> then <EM>a</EM>.
1558  <P></P>  <P></P>
1559    <DT><STRONG><A NAME="item_If_d_does_not_run">If <EM>d</EM> does not run</A></STRONG><BR>
1560    <DD>
1561    When monit runs it will first stop <EM>a</EM>, <EM>b</EM> and <EM>c</EM> then start
1562    <EM>d</EM> and finally start <EM>c</EM>, <EM>b</EM> then <EM>a</EM>.
1563    <P></P>
1564  <DT><STRONG><A NAME="item_If_the_control_file_contains_a_depend_loop%2E">If the control file contains a depend loop.</A></STRONG><BR>  <DT><STRONG><A NAME="item_If_the_control_file_contains_a_depend_loop%2E">If the control file contains a depend loop.</A></STRONG><BR>
1565  <DD>  <DD>
1566  A depend loop is for example; a-&gt;b and b-&gt;a or a-&gt;b-&gt;c-&gt;a.  A depend loop is for example; a-&gt;b and b-&gt;a or a-&gt;b-&gt;c-&gt;a.
1567  <P>When monit starts it will check for any such loops and complain  <P>When monit starts it will check for any such loops and complain
1568  and exit if a loop was found. It will also exit with a complaint  and exit if a loop was found. It will also exit with a complaint
1569  if a depend statement was used that does not point to any process  if a depend statement was used that does not point to any service
1570  in the controlfile.</P>  in the controlfile.</P>
1571  <P></P></DL>  <P></P></DL>
1572  <P>  <P>
# Line 910  complain and exit otherwise.</P> Line 1582  complain and exit otherwise.</P>
1582  <P>  <P>
1583  <H2><A NAME="run control syntax">Run Control Syntax</A></H2>  <H2><A NAME="run control syntax">Run Control Syntax</A></H2>
1584  <P>Comments begin with a '#' and extend through the end of the line.  <P>Comments begin with a '#' and extend through the end of the line.
1585  Otherwise the file consists of a series of program entries or  Otherwise the file consists of a series of service entries or
1586  global option statements in a free-format, token-oriented syntax.</P>  global option statements in a free-format, token-oriented syntax.</P>
1587  <P>There are three kinds of tokens: grammar keywords, numbers (i.e.  <P>There are three kinds of tokens: grammar keywords, numbers (i.e.
1588  decimal digit sequences) and strings. Strings can be either  decimal digit sequences) and strings. Strings can be either
# Line 918  quoted or unquoted. A quoted string is b Line 1590  quoted or unquoted. A quoted string is b
1590  and may contain whitespace (and quoted digits are treated as a  and may contain whitespace (and quoted digits are treated as a
1591  string).  An unquoted string is any whitespace-delimited token,  string).  An unquoted string is any whitespace-delimited token,
1592  containing characters and/or numbers.</P>  containing characters and/or numbers.</P>
1593  <P>Each program entry consists of the keywords `check', followed by  <P>Each service entry consists of the keywords `check', followed by
1594  a unique descriptive name for the program, which is again  a type of service. There are currently four types of services
1595  followed by a path to the program's pidfile. A check entry can  supported:</P>
1596  have a number of optional statements. These statements are  <P>1.) device
1597  described below and in the example section.</P>  2.) directory
1598    3.) file
1599    4.) process</P>
1600    <P>Unique descriptive name for the service follows service type
1601    specification. It is used by monit to refer this service
1602    internally and in all interactions with user.</P>
1603    <P>Name is followed by `path' keyword which is followed depending on
1604    the type of service:</P>
1605    <P>1.) device
1606     By a path to the device block special file, mountpoint, file
1607     or directory which is part of the filesystem. It is recommended
1608     to use block special file directly (for example /dev/hda1 on
1609     Linux or /dev/dsk/c0t0d0s1 on Solaris, etc.) If you use
1610     mountpoint (for example /data), be carefull, because if the
1611     device is dismounted it still exists but it is part of superior
1612     filesystem.</P>
1613    <PRE>
1614     In the case that the device becomes unavailable, monit will
1615     call start/stop methods whenever defined if it is running in
1616     active mode. In the case that it is running in passive mode or
1617     start/stop methods were not defined, it will just send failure
1618     alert.</PRE>
1619    <P>2.) directory
1620     By a path to the directory (surprise :)</P>
1621    <PRE>
1622     In the case that the directory doesn't exist any more
1623     monit will call start/stop methods whenever defined if it is
1624     running in active mode. In the case that it is running in
1625     passive mode or start/stop methods were not defined, it will
1626     just send failure alert.</PRE>
1627    <P>3.) file
1628     By a path to the file.</P>
1629    <PRE>
1630     In the case that the file doesn't exist any more
1631     monit will call start/stop methods whenever defined if it is
1632     running in active mode. In the case that it is running in
1633     passive mode or start/stop methods were not defined, it will
1634     just send failure alert.</PRE>
1635    <P>4.) process
1636     By a path to the program's pidfile. For this type of service you
1637     can use keyword `pidfile' as predecesor of pidfile path instead
1638     of `path' keyword (for backward compatibility).</P>
1639    <P>A check entry can have a number of optional statements. Each type
1640    of service (device, directory, file, process) supports subset of
1641    these options, complete list follows:</P>
1642    <PRE>
1643     check device service1 with path /dev/hdb1
1644      start
1645      stop
1646      timeout
1647      every
1648      alert
1649      mode
1650      group
1651      depend
1652      inode
1653      space
1654      permission
1655      uid
1656      gid</PRE>
1657    <PRE>
1658     check directory service2 with path /mydir
1659      start
1660      stop
1661      timeout
1662      every
1663      alert
1664      mode
1665      group
1666      depend
1667      timestamp
1668      permission
1669      uid
1670      gid</PRE>
1671    <PRE>
1672     check file service3 with path /mydir/myfile
1673      start
1674      stop
1675      timeout
1676      every
1677      alert
1678      mode
1679      group
1680      depend
1681      checksum
1682      timestamp
1683      permission
1684      uid
1685      gid</PRE>
1686    <PRE>
1687     check [process] service4 with {pidfile|path} /var/run/myproc.pid
1688      start
1689      stop
1690      host
1691      unixsocket
1692      resource
1693      timeout
1694      every
1695      alert
1696      mode
1697      group
1698      depend</PRE>
1699    <P>These statements are described below and in the example section.</P>
1700  <P>You can use noise keywords like 'if', `and', `with(in)', `has',  <P>You can use noise keywords like 'if', `and', `with(in)', `has',
1701  `using', 'use', 'on(ly)' and `program' anywhere in an entry to  `using', 'use', 'on(ly)', `usage' and `program(s)' anywhere in
1702  make it resemble English. They're ignored, but can make entries  an entry to make it resemble English. They're ignored, but can
1703  much easier to read at a glance. The punctuation characters ';'  make entries much easier to read at a glance. The punctuation
1704  ',' and '=' are also ignored. Keywords are case insensitive.</P>  characters ';' ',' and '=' are also ignored. Keywords are case
1705    insensitive.</P>
1706  <PRE>  <PRE>
1707   Here are the legal global keywords:</PRE>   Here are the legal global keywords:</PRE>
1708  <PRE>  <PRE>
# Line 938  much easier to read at a glance. The pun Line 1713  much easier to read at a glance. The pun
1713   set logfile     Name of a file to dump error- and status-   set logfile     Name of a file to dump error- and status-
1714                   messages to. If syslog is specified as the                   messages to. If syslog is specified as the
1715                   file, monit will utilize the syslog daemon                   file, monit will utilize the syslog daemon
1716                   to log messages.                   to log messages. This can optionally be
1717                     followed by 'facility &lt;facility&gt;' where
1718                     facility is 'log_local0' - 'log_local7' or
1719                     'log_daemon'. If no facility is specified,
1720                     LOG_USER is used.</PRE>
1721    <PRE>
1722   set mailserver  The mailserver used for sending alert   set mailserver  The mailserver used for sending alert
1723                   notifications. If the mailserver is not                   notifications. If the mailserver is not
1724                   defined, monit will try to use 'localhost'                   defined, monit will try to use 'localhost'
# Line 947  much easier to read at a glance. The pun Line 1727  much easier to read at a glance. The pun
1727                   messages emitted by monit.                   messages emitted by monit.
1728   set pidfile     Explicit set the location of the monit lock   set pidfile     Explicit set the location of the monit lock
1729                   file. E.g. set pidfile /run/monit.pid.                   file. E.g. set pidfile /run/monit.pid.
1730     set statefile   Explicit set the location of file monit
1731                     will write state data to. If not set the
1732                     default is $HOME/.monit.state.
1733   set httpd port  Activates monit http server at the given   set httpd port  Activates monit http server at the given
1734                   portnumber.                   portnumber.
1735   ssl enable      Enables ssl support for the httpd server.   ssl enable      Enables ssl support for the httpd server.
# Line 967  much easier to read at a glance. The pun Line 1750  much easier to read at a glance. The pun
1750                   are allowed. This statement is also an                   are allowed. This statement is also an
1751                   optional part of the set httpd statement.</PRE>                   optional part of the set httpd statement.</PRE>
1752  <PRE>  <PRE>
1753   Here are the legal program entry keywords:</PRE>   Here are the legal service entry keywords:</PRE>
1754  <PRE>  <PRE>
1755   Keyword         Function   Keyword         Function
1756   ------------------------------------------------------------   ------------------------------------------------------------
1757   check           Starts an entry and must be followed by a   check           Starts an entry and must be followed by type
1758                   descriptive name for the program.                   of monitored service {device|directory|file|
1759   pidfile         Specify the  programs pidfile. Every                   process} and descriptive name for the service.
1760                   program must create a pidfile with its   pidfile         Specify the  process pidfile. Every
1761                   current process id                   process must create a pidfile with its
1762   group           Specify a groupname for a program entry.                   current process id. This statement is possible
1763                     to use with process monitoring type only (for
1764                     backward compatibility). You can use path
1765                     statement with process monitoring type as well
1766                     (see bellow).
1767     path            Must be followed by a path to the block
1768                     special file for filesystem (device), regular
1769                     file, directory or process's pidfile.
1770     group           Specify a groupname for a service entry.
1771   start           The program for starting the specified   start           The program for starting the specified
1772                   process. Full path is required. This                   service. Full path is required. This
1773                   statement is optional.                   statement is optional.
1774   stop            The program for stopping the specified   stop            The program for stopping the specified
1775                   process -- full path is required. This                   service. Full path is required. This
1776                   statement is optional.                   statement is optional.
1777     uid and gid     Either optional part of a start, stop or exec
1778                     statement (then it may be used to specify a user
1779                     id and a group id the program should be started
1780                     as) or standalone statement of file service
1781                     check. The uid and gid may be specified as a
1782                     name or as a number. The first form of this
1783                     extension may only be used if the super-user
1784                     is running monit.
1785   host            The hostname or IP address to test the port   host            The hostname or IP address to test the port
1786                   at. This keyword can only be used together                   at. This keyword can only be used together
1787                   with a port statement.                   with a port statement.
# Line 1008  much easier to read at a glance. The pun Line 1807  much easier to read at a glance. The pun
1807   proto(col)      This keyword specifies the type of service   proto(col)      This keyword specifies the type of service
1808                   found at the port. monit knows at the moment                   found at the port. monit knows at the moment
1809                   how to speak HTTP, SMTP, FTP, POP, IMAP, NNTP,                   how to speak HTTP, SMTP, FTP, POP, IMAP, NNTP,
1810                   SSH, DWP, LDAP2 and LDAP3. You're welcome                   SSH, DWP, LDAP2, LDAP3 and RDATE. You're welcome
1811                   to write new protocol test modules. If no                   to write new protocol test modules. If no
1812                   protocol is specified monit will use a default                   protocol is specified monit will use a default
1813                   test which in most cases are good enough.                   test which in most cases are good enough.
# Line 1021  much easier to read at a glance. The pun Line 1820  much easier to read at a glance. The pun
1820   unix(socket)    Specifies a unix socket file and used like   unix(socket)    Specifies a unix socket file and used like
1821                   the port statement above to test a Unix                   the port statement above to test a Unix
1822                   domain network socket connection.                   domain network socket connection.
1823   timeout         Define program timeout.  Must be followed by   timeout x sec.  Define a network port connection timeout. Must
1824                     be followed by a number in seconds and the
1825                     keyword, seconds.
1826     timeout         Define service timeout. Must be followed by
1827                   two digits. The first digit is max number of                   two digits. The first digit is max number of
1828                   restarts for  the program.  The second digit                   restarts for the service. The second digit
1829                   is the cycle interval to test restarts.                   is the cycle interval to test restarts.
1830                   This statement is optional                   This statement is optional
1831   alert           Specifies an email address for notification   alert           Specifies an email address for notification
1832                   if checksum, timeout, restart, stop or timestamp                   if timeout, start, restart, checksum, resource,
1833                   occurs.  Alert can also be postfixed, to only                   stop, connection, size, permission, uid, gid,
1834                   send a message for certain events. See the                   unmonitor or timestamp occurs. Alert can also
1835                   examples above. More than one alert statement                   be postfixed, to only send a message for
1836                   is allowed in an entry. This statement is also                   certain events. See the examples above. More
1837                   optional.                   than one alert statement is allowed in an
1838                     entry. This statement is also optional.
1839     restart, stop   These keywords may be used as actions for
1840     unmonitor and   various test statements. The exec statement is
1841     exec            special in that it requires a following string
1842                     specifying the program to be execute. You may
1843                     also specify an UID and GID to the exec
1844                     statement. The program executed will then run
1845                     using the specified user id and group id.
1846   mail-format     Specifies a mail format for an alert message   mail-format     Specifies a mail format for an alert message
1847                   This statement is an optional part of the                   This statement is an optional part of the
1848                   alert statement.                   alert statement.
1849   checksum        Specify that monit should verify a checksum   checksum        Specify that monit should verify a checksum
1850                   for associated files.                   for associated file.
1851                   More than one checksum statement are allowed.                   More than one checksum statement are allowed.
1852   expect          Specifies a checksum string (md5) monit   expect          Specifies a checksum string (md5) monit
1853                   should use when testing the checksum. This                   should use when testing the checksum. This
1854                   statement is an optional part of the                   statement is an optional part of the
1855                   checksum statement.                   checksum statement.
1856   timestamp       Specifies expected timestamp for given object   timestamp       Specifies expected timestamp for associated file
1857                   and optional action. More than one timeout                   or directory and optional action. More than one
1858                   statement are allowed.                   timeout statement are allowed.
1859     changed         Part of a time statement and used as an operator
1860                     to simply test for a timestamp change.
1861   every           Validate this entry only at every n poll   every           Validate this entry only at every n poll
1862                   cycle. Usefull in daemon mode when the                   cycle. Usefull in daemon mode when the
1863                   poll-cycle is short and the program takes                   poll-cycle is short and the service takes
1864                   some time to start.                   some time to start.
1865   mode            Must be followed either by the keyword active,   mode            Must be followed either by the keyword active,
1866                   passive or manual. If active, monit will restart                   passive or manual. If active, monit will restart
1867                   the program if it is not running (this is the                   the service if it is not running (this is the
1868                   default behaviour). If passive, monit will not                   default behaviour). If passive, monit will not
1869                   (re)start the program if it is not running - it                   (re)start the service if it is not running - it
1870                   will only monitor and send alerts (resource                   will only monitor and send alerts (resource
1871                   related restart and stop options are ignored                   related restart and stop options are ignored
1872                   in this mode also). If manual, monit will enter                   in this mode also). If manual, monit will enter
1873                   active mode only if a service was started under                   active mode only if a service was started under
1874                   monit's control otherwise the service isn't                   monit's control otherwise the service isn't
1875                   monitored.                   monitored.
1876   cpuusage        Must be followed by a compare operator, a   cpu             Must be followed by a compare operator, a number
1877                   floating point number, optionally a maximum                   with &quot;%&quot;, optionally a maximum number of cycles
1878                   number of cycles and an action. This statement                   and an action. This statement is used to check
1879                   is used to check the cpu usage in percent of a                   the cpu usage in percent of a process with it's
1880                   process with it's children over a number of                   children over a number of cylces.  If the
1881                   cylces.  If the compare expression matches then                   compare expression matches then the action
1882                   the action restart, alert or stop is activated                   restart, alert or stop is activated.
1883   memusage        The equivalent to cpuusage for memory of a   mem             The equivalent to the cpu token for memory of a
1884                   process (w/o children!). The syntax is the same                   process (w/o children!).  This token must be
1885                   as above.                   followed by a compare operator a number with
1886   memkbyte        The equivalent to memusage but with amounts                   unit {B|KB|MB|GB|%|byte|kilobyte|megabyte|
1887                   in Kb instead of percentages.                   gigabyte|percent}, optionally a maximum number
1888                     of cycles and an action.
1889   loadavg         Must be followed by [1min,5min,15min] in (), a   loadavg         Must be followed by [1min,5min,15min] in (), a
1890                   compare operator, a floating point number,                   compare operator, a number, optionally a maximum
1891                   optionally a maximum number of cycles and an                   number of cycles and an action.  
1892                   action.  This statement is used to check the                   This statement is used to check the system load
1893                   system load average over a number of cylces. If                   average over a number of cylces. If the compare
1894                   the compare expression matches then the action                   expression matches then the action start, alert
1895                   start, alert or stop is avtivated.                   or stop is activated.
1896   depends (on)    Must be followed by the name of a process this   children        This is the number of child processes of a
1897                   process depends on to run before it starts.</PRE>                   process. The syntax is the same as above.
1898     totalmem        The equivalent to memory for memory of a
1899                     process and it's child processes. The syntax
1900                     is the same as above.
1901     space           Must be followed by a compare operator, a
1902                     number, unit {B|KB|MB|GB|%|byte|kilobyte|
1903                     megabyte|gigabyte|percent} and action.
1904     inode(s)        Must be followed by a compare operator, integer
1905                     number, optionaly by percent sign (if not, the
1906                     limit is absolute) and action (required).
1907     perm(ission)    Must be followed by an octal number describing
1908                     permissions.
1909     size            Must be followed by a compare operator, a
1910                     number, unit {B|KB|MB|GB|byte|kilobyte|
1911                     megabyte|gigabyte} and action.
1912     depends (on)    Must be followed by the name of a service this
1913                     service depends on to run before it starts.</PRE>
1914  <P>Here's the complete list of reserved <STRONG>keywords</STRONG> used by monit:</P>  <P>Here's the complete list of reserved <STRONG>keywords</STRONG> used by monit:</P>
1915  <P><EM>set</EM>, <EM>daemon</EM>, <EM>logfile</EM>, <EM>syslog</EM>, <EM>address</EM>, <EM>httpd</EM>,  <P><EM>if</EM>, <EM>then</EM>, <EM>else</EM>, <EM>set</EM>, <EM>daemon</EM>, <EM>logfile</EM>,
1916  <EM>ssl</EM>, <EM>enable</EM>, <EM>disable</EM>, <EM>pemfile</EM>, <EM>allow</EM>, <EM>check</EM>,  <EM>syslog</EM>, <EM>address</EM>, <EM>httpd</EM>, <EM>ssl</EM>, <EM>enable</EM>, <EM>disable</EM>,
1917  <EM>init</EM>, <EM>pidfile</EM>, <EM>group</EM>, <EM>start</EM>, <EM>stop</EM>,  <EM>pemfile</EM>, <EM>allow</EM>, <EM>check</EM>, <EM>init</EM>, <EM>pidfile</EM>,
1918  <EM>port(number)</EM>, <EM>unix(socket)</EM>, <EM>type</EM>, <EM>proto(col)</EM>, <EM>tcp</EM>,  <EM>statefile</EM>, <EM>group</EM>, <EM>start</EM>, <EM>stop</EM>, <EM>uid</EM>, <EM>gid</EM>,
1919  <EM>tcpssl</EM>, <EM>udp</EM>, <EM>alert</EM>, <EM>mail-format</EM>, <EM>restart</EM>,  <EM>connection</EM>, <EM>port(number)</EM>, <EM>unix(socket)</EM>, <EM>type</EM>,
1920  <EM>timeout</EM>, <EM>checksum</EM>, <EM>resource</EM>, <EM>expect</EM>, <EM>mailserver</EM>,  <EM>proto(col)</EM>, <EM>tcp</EM>, <EM>tcpssl</EM>, <EM>udp</EM>, <EM>alert</EM>,
1921  <EM>every</EM>, <EM>mode</EM>, <EM>active</EM>, <EM>passive</EM>, <EM>manual</EM>, <EM>depends</EM>,  <EM>mail-format</EM>, <EM>restart</EM>, <EM>timeout</EM>, <EM>checksum</EM>, <EM>resource</EM>,
1922  <EM>host</EM>, <EM>default</EM>, <EM>http</EM>, <EM>ftp</EM>, <EM>smtp</EM>, <EM>pop</EM>, <EM>nntp</EM>,  <EM>expect</EM>, <EM>mailserver</EM>, <EM>every</EM>, <EM>mode</EM>, <EM>active</EM>,
1923  <EM>imap</EM>, <EM>ssh</EM>, <EM>dwp</EM>, <EM>ldap2</EM>, <EM>ldap3</EM>, <EM>request</EM>,  <EM>passive</EM>, <EM>manual</EM>, <EM>depends</EM>, <EM>host</EM>, <EM>default</EM>, <EM>http</EM>,
1924  <EM>cpuusage</EM>, <EM>memusage</EM>, <EM>memkbyte</EM>, <EM>loadavg</EM>, <EM>timestamp</EM>,  <EM>ftp</EM>, <EM>smtp</EM>, <EM>pop</EM>, <EM>nntp</EM>, <EM>imap</EM>, <EM>ssh</EM>, <EM>dwp</EM>,
1925  <EM>second(s)</EM>, <EM>minute(s)</EM>, <EM>hour(s)</EM> and <EM>day(s)</EM>.</P>  <EM>ldap2</EM>, <EM>ldap3</EM>, <EM>request</EM>, <EM>cpu</EM>, <EM>mem</EM>, <EM>totalmem</EM>,
1926    <EM>children</EM>, <EM>loadavg</EM>, <EM>timestamp</EM>, <EM>changed</EM>, <EM>second(s)</EM>,
1927    <EM>minute(s)</EM>, <EM>hour(s)</EM>, <EM>day(s)</EM>, <EM>space</EM>, <EM>inode</EM>,
1928    <EM>perm(ission)</EM>, <EM>process</EM>, <EM>file</EM>, <EM>directory</EM>, <EM>device</EM>,
1929    <EM>size</EM>, <EM>unmonitor</EM> and <EM>failed</EM></P>
1930  <P>And here is a complete list of <STRONG>noise keywords</STRONG> ignored by  <P>And here is a complete list of <STRONG>noise keywords</STRONG> ignored by
1931  monit:</P>  monit:</P>
1932  <P><EM>if</EM>, <EM>is</EM>, <EM>are</EM>, <EM>on(ly)</EM>, <EM>with(in)</EM>, <EM>and</EM>, <EM>has</EM>,  <P><EM>is</EM>, <EM>are</EM>, <EM>on(ly)</EM>, <EM>with(in)</EM>, <EM>and</EM>, <EM>has</EM>, <EM>using</EM>,
1933  <EM>using</EM>, <EM>use</EM>, <EM>the</EM>, <EM>sum</EM>, <EM>restarts</EM>, <EM>program(s)</EM>,  <EM>use</EM>, <EM>the</EM>, <EM>sum</EM>, <EM>program(s)</EM>, <EM>cycle(s)</EM>, <EM>than</EM>,
1934  <EM>cycle(s)</EM>, <EM>than</EM>, <EM>then</EM>, <EM>for</EM>.</P>  <EM>for</EM>, <EM>usage</EM>, <EM>was</EM>.</P>
1935  <P><STRONG>Note:</STRONG> If the <EM>start</EM> or <EM>stop</EM> programs are shell scripts,  <P><STRONG>Note:</STRONG> If the <EM>start</EM> or <EM>stop</EM> programs are shell scripts,
1936  then the script must begin with <CODE>#!</CODE> and the remainder of the  then the script must begin with <CODE>#!</CODE> and the remainder of the
1937  first line must specify an interpreter for the  first line must specify an interpreter for the
1938  program. E.g. <CODE>#!/bin/sh</CODE></P>  program. E.g. <CODE>#!/bin/sh</CODE></P>
1939  <P>It's possible to write scripts directly into the <EM>start</EM> and  <P>It's possible to write scripts directly into the <EM>start</EM> and
1940  <EM>stop</EM> entries by using a string of shell-commands. Like:</P>  <EM>stop</EM> entries by using a string of shell-commands. Like so:</P>
1941  <PRE>  <PRE>
1942   start: &quot;/bin/sh -c { echo $$ &gt; pidfile; exec program }&quot;   start=&quot;/bin/bash -c 'echo $$ &gt; pidfile; exec program'&quot;
1943   stop:  &quot;/bin/sh -c { kill -s SIGTERM `cat pidfile` }&quot;</PRE>   stop=&quot;/bin/bash -c 'kill -s SIGTERM `cat pidfile`'&quot;</PRE>
1944    <P>When a program is started by monit</P>
1945  <P>  <P>
1946  <H2><A NAME="configuration examples">CONFIGURATION EXAMPLES</A></H2>  <H2><A NAME="configuration examples">CONFIGURATION EXAMPLES</A></H2>
1947  <P>The simplest form is just the check statement. In this example we  <P>The simplest form is just the check statement. In this example we
1948  check to see if the server is running and log a message if not:</P>  check to see if the server is running and log a message if not:</P>
1949  <PRE>  <PRE>
1950   check resin with pidfile /usr/local/resin/srun.pid</PRE>   check process resin with pidfile /usr/local/resin/srun.pid</PRE>
1951  <P>To have monit start the server if it's not running, add a start  <P>To have monit start the server if it's not running, add a start
1952  statement:</P>  statement:</P>
1953  <PRE>  <PRE>
1954   check resin with pidfile /usr/local/resin/srun.pid   check process resin with pidfile /usr/local/resin/srun.pid
1955     start program = &quot;/usr/local/resin/bin/srun.sh start&quot;</PRE>     start program = &quot;/usr/local/resin/bin/srun.sh start&quot;</PRE>
1956  <P>Here's a more advanced example for monitoring an apache  <P>Here's a more advanced example for monitoring an apache
1957  web-server listening on the default portnumber for HTTP and  web-server listening on the default portnumber for HTTP and
1958  HTTPS. In this example monit will restart apache if it's not  HTTPS. In this example monit will restart apache if it's not
1959  accepting connections at the portnumbers. The method monit use  accepting connections at the portnumbers. The method monit use
1960  for a process restart is to first execute the stop-program, wait  for a process restart is to first execute the stop-program, wait
1961  for the process to stop and then execute the start-program.</P>  for the process to stop and then execute the start-program. (If
1962    monit was unable to stop or start the service a failed alert
1963    message will be sent if you have requested alert messages to be
1964    sent).</P>
1965  <PRE>  <PRE>
1966   check apache with pidfile /var/run/httpd.pid   check process apache with pidfile /var/run/httpd.pid
1967     start program = &quot;/etc/init.d/httpd start&quot;     start program = &quot;/etc/init.d/httpd start&quot;
1968     stop program  = &quot;/etc/init.d/httpd stop&quot;     stop program  = &quot;/etc/init.d/httpd stop&quot;
1969     port 80       if failed port 80 then restart
1970     port 443</PRE>     if failed port 443 with timeout 15 seconds then restart</PRE>
1971    <P>This example demonstrate how you can run a program as a specified
1972    user (uid) and with a specified group (gid). Many daemon programs
1973    will do the uid and gid switch by themself, but for those
1974    programs that does not (e.g. java programs), monit's ability to
1975    start a program as a certain user can be very useful.  In this
1976    example we start the Tomcat Java Servlet Engine as the standard
1977    <EM>nobody</EM> user and group. Please note that monit will only change
1978    uid and gid for a program if the super-user is running monit,
1979    otherwise monit will simply ignore the request to change uid and
1980    gid.</P>
1981    <PRE>
1982     check tomcat with pidfile /var/run/tomcat.pid
1983       start program = &quot;/etc/init.d/tomcat start&quot;
1984          as uid nobody and gid nobody
1985       stop program  = &quot;/etc/init.d/tomcat stop&quot;
1986          # You can also use id numbers instead and write:
1987          as uid 99 and with gid 99
1988       if failed port 8080 then alert</PRE>
1989  <P>In this example we use udp for connection testing to check if the  <P>In this example we use udp for connection testing to check if the
1990  'named' service is running and also use timeout and alert:</P>  'named' service is running and also use timeout and alert:</P>
1991  <PRE>  <PRE>
1992   check named with pidfile /var/run/named.pid   check process named with pidfile /var/run/named.pid
1993     start program = &quot;/etc/init.d/named start&quot;     start program = &quot;/etc/init.d/named start&quot;
1994     stop program  = &quot;/etc/init.d/named stop&quot;     stop program  = &quot;/etc/init.d/named stop&quot;
1995     port 53 use type udp     if failed port 53 use type udp then restart
1996     timeout (3,5)     if 3 restarts within 5 cycles then timeout
1997     alert bofh@norid.no</PRE>     alert bofh@norid.no</PRE>
1998  <P>The following example illustrate how to check if the service  <P>The following example illustrate how to check if the service
1999  'sophie' is answering connections on its unix domain socket:</P>  'sophie' is answering connections on its unix domain socket:</P>
2000  <PRE>  <PRE>
2001   check sophie with pidfile /var/run/sophie.pid   check process sophie with pidfile /var/run/sophie.pid
2002     start program = &quot;/etc/init.d/sophie start&quot;     start program = &quot;/etc/init.d/sophie start&quot;
2003     stop  program = &quot;/etc/init.d/sophie stop&quot;     stop  program = &quot;/etc/init.d/sophie stop&quot;
2004     unix /var/run/sophie</PRE>     if failed unix /var/run/sophie then restart</PRE>
2005  <P>In this example we check an apache web-server running on  <P>In this example we check an apache web-server running on
2006  localhost that answers for several IP-based virtual hosts or  localhost that answers for several IP-based virtual hosts or
2007  vhosts, hence the host statement before port:</P>  vhosts, hence the host statement before port:</P>
2008  <PRE>  <PRE>
2009   check apache with pidfile /var/run/httpd.pid   check process apache with pidfile /var/run/httpd.pid
2010     start program = &quot;/etc/init.d/httpd start&quot;     start program = &quot;/etc/init.d/httpd start&quot;
2011     stop program  = &quot;/etc/init.d/httpd stop&quot;     stop program  = &quot;/etc/init.d/httpd stop&quot;
2012     host www.sol.no          port 80     if failed host www.sol.no port 80 then alert
2013     host shop.sol.no         port 443     if failed host shop.sol.no port 443 then alert
2014     host chat.sol.no         port 80     if failed host chat.sol.no port 80 then alert
2015     host www.tildeslash.com  port 80</PRE>     if failed host www.tildeslash.com port 80 then alert</PRE>
2016  <P>In the following example we ask monit to compute and verify the  <P>In the following example we ask monit to compute and verify the
2017  checksum for the underlying apache binary used by the start and  checksum for the underlying apache binary used by the start and
2018  stop programs.</P>  stop programs. In the case that the chaksum will fail, the
2019    monitoring will be disabled to prevent compromited binary
2020    execution:</P>
2021  <PRE>  <PRE>
2022   check apache with pidfile /var/run/httpd.pid   check process apache with pidfile /var/run/httpd.pid
2023     start program = &quot;/etc/init.d/httpd start&quot;     start program = &quot;/etc/init.d/httpd start&quot;
2024     stop program  = &quot;/etc/init.d/httpd stop&quot;     stop program  = &quot;/etc/init.d/httpd stop&quot;
2025     host www.tildeslash.com  port 80     if failed host www.tildeslash.com port 80 then restart
2026     checksum /usr/local/apache/bin/httpd</PRE>     depends on apache_bin</PRE>
2027    <PRE>
2028     check file apache_bin with path /usr/local/apache/bin/httpd
2029       if failed checksum then unmonitor</PRE>
2030  <P>Some servers are slow starters, like for example Java based  <P>Some servers are slow starters, like for example Java based
2031  Application Servers. So if we want to keep the poll-cycle low  Application Servers. So if we want to keep the poll-cycle low
2032  (i.e. &lt; 60 seconds) but allow some programs to take its time to  (i.e. &lt; 60 seconds) but allow some services to take its time to
2033  start, the <STRONG>every</STRONG> statement is handy:</P>  start, the <STRONG>every</STRONG> statement is handy:</P>
2034  <PRE>  <PRE>
2035   check dynamo with pidfile /etc/dynamo.pid   check process dynamo with pidfile /etc/dynamo.pid
2036     start program = &quot;/etc/init.d/dynamo start&quot;     start program = &quot;/etc/init.d/dynamo start&quot;
2037     stop program  = &quot;/etc/init.d/dynamo stop&quot;     stop program  = &quot;/etc/init.d/dynamo stop&quot;
2038     port 8840     if failed port 8840 then alert
2039     every 2 cycle</PRE>     every 2 cycle</PRE>
2040  <P>Here is an example where we group together two database entries.  <P>Here is an example where we group together two database entries.
2041  The mode statement is also illustrated in the first entry and  The mode statement is also illustrated in the first entry and
2042  have the effect that monit will not try to (re)start this program  have the effect that monit will not try to (re)start this service
2043  if it is not running:</P>  if it is not running:</P>
2044  <PRE>  <PRE>
2045   check sybase with pidfile /var/run/sybase.pid   check process sybase with pidfile /var/run/sybase.pid
2046     start program = &quot;/etc/init.d/sybase start&quot;     start program = &quot;/etc/init.d/sybase start&quot;
2047     stop program  = &quot;/etc/init.d/sybase stop&quot;     stop program  = &quot;/etc/init.d/sybase stop&quot;
2048     mode passive     mode passive
2049     group database</PRE>     group database</PRE>
2050  <PRE>  <PRE>
2051   check oracle with pidfile /var/run/oracle.pid   check process oracle with pidfile /var/run/oracle.pid
2052     start program = &quot;/etc/init.d/oracle start&quot;     start program = &quot;/etc/init.d/oracle start&quot;
2053     stop program  = &quot;/etc/init.d/oracle stop&quot;     stop program  = &quot;/etc/init.d/oracle stop&quot;
2054     mode active # Not necessary really, since this is the default     mode active # Not necessary really, since this is the default
2055     port 9001     if failed port 9001 then restart
2056     alert bofh@foo.bar     alert bofh@foo.bar
2057     group database</PRE>     group database</PRE>
2058  <P>Here is an example to show the usage of the resource checks. It  <P>Here is an example to show the usage of the resource checks. It
2059  will send an alert when the CPU usage of the http daemon and it's  will send an alert when the CPU usage of the http daemon and it's
2060  child processes raises beyond 60% for over two cycles.  It is  child processes raises beyond 60% for over two cycles.  It is
2061  restarted when the CPU usage it over 80% for five cycles, the  restarted when the CPU usage if over 80% for five cycles, the
2062  memory usage over 100Mb for five cycles or if the machines load  memory usage over 100Mb for five cycles or if the machines load
2063  average is beyond 10 for 8 cycles:</P>  average is beyond 10 for 8 cycles:</P>
2064  <PRE>  <PRE>
2065   check apache with pidfile /var/run/httpd.pid   check process apache with pidfile /var/run/httpd.pid
2066     start program = &quot;/etc/init.d/httpd start&quot;     start program = &quot;/etc/init.d/httpd start&quot;
2067     stop program  = &quot;/etc/init.d/httpd stop&quot;     stop program  = &quot;/etc/init.d/httpd stop&quot;
2068     if cpuusage &gt; 60.0 for 2 cycles then alert     if cpu &gt; 60% for 2 cycles then alert
2069     if cpuusage &gt; 80.0 for 5 cycles then restart     if cpu &gt; 80% for 5 cycles then restart
2070     if memkbyte &gt; 100000 for 5 cycles then stop     if mem &gt; 100 MB for 5 cycles then stop
2071     if loadavg(5min) greater than 10.0 for 8 cycles then stop</PRE>     if loadavg(5min) greater than 10.0 for 8 cycles then stop</PRE>
2072    <P>This examples demonstrate the timestamp statement with exec and
2073    how you may restart apache if it's configuration file was
2074    changed.</P>
2075    <PRE>
2076     check file httpd.conf with path /usr/local/apache/conf/httpd.conf
2077       if timestamp was changed then exec &quot;/etc/init.d/httpd graceful&quot;</PRE>
2078  <P>In this example we demonstrate usage of the extended alert  <P>In this example we demonstrate usage of the extended alert
2079  statement:</P>  statement and file check dependency:</P>
2080  <PRE>  <PRE>
2081   check apache with pidfile /var/run/httpd.pid   check process apache with pidfile /var/run/httpd.pid
2082     start program = &quot;/etc/init.d/httpd start&quot;     start program = &quot;/etc/init.d/httpd start&quot;
2083     stop program  = &quot;/etc/init.d/httpd stop&quot;     stop program  = &quot;/etc/init.d/httpd stop&quot;
2084     host www.tildeslash.com  port 80     if failed host www.tildeslash.com  port 80 then restart
    checksum /usr/local/apache/bin/httpd  
    alert security@bar on {checksum}  
      with mail-format {subject: Alaaarrm! on $HOST}  
2085     alert admin@bar on {restart, timeout}     alert admin@bar on {restart, timeout}
2086       with mail-format {       with mail-format {
2087                from:     bofh@$HOST                from:     bofh@$HOST
# Line 1228  statement:</P> Line 2091  statement:</P>
2091                Your faithful employee,                Your faithful employee,
2092                monit                monit
2093       }       }
2094     timeout (3, 5)     if 3 restarts within 5 cycles then timeout
2095     group server</PRE>     depend httpd_bin
2096       group apache</PRE>
2097    <PRE>
2098     check file httpd_bin with path /usr/local/apache/bin/httpd
2099       if failed checksum and expect 8f7f419955cefa0b33a2ba316cba3659
2100         then unmonitor
2101       if failed permission 755 then unmonitor
2102       if failed uid root then unmonitor
2103       if failed gid root then unmonitor
2104       if size changed then alert
2105       if timestamp changed then alert
2106       alert security@bar on {checksum, size, timestamp, permission,
2107         uid, gid, unmonitor} with mail-format
2108         {subject: Alaaarrm! on $HOST}
2109       group apache</PRE>
2110  <P>In this example, we demonstrate usage of the depend statement. In  <P>In this example, we demonstrate usage of the depend statement. In
2111  this case, we want to start oracle and apache. However, we've set  this case, we want to start oracle and apache. However, we've set
2112  up apache to use oracle as a backend, and if oracle is restarted,  up apache to use oracle as a backend, and if oracle is restarted,
2113  apache must be restarted as well.</P>  apache must be restarted as well.</P>
2114  <PRE>  <PRE>
2115   check apache with pidfile /var/run/httpd.pid   check process apache with pidfile /var/run/httpd.pid
2116     start program = &quot;/etc/init.d/httpd start&quot;     start program = &quot;/etc/init.d/httpd start&quot;
2117     stop  program = &quot;/etc/init.d/httpd stop&quot;     stop  program = &quot;/etc/init.d/httpd stop&quot;
2118     depends on oracle</PRE>     depends on oracle</PRE>
2119  <PRE>  <PRE>
2120   check oracle with pidfile /var/run/oracle.pid   check process oracle with pidfile /var/run/oracle.pid
2121     start program = &quot;/etc/init.d/oracle start&quot;     start program = &quot;/etc/init.d/oracle start&quot;
2122     stop program  = &quot;/etc/init.d/oracle stop&quot;     stop program  = &quot;/etc/init.d/oracle stop&quot;
2123     port 9001</PRE>     if failed port 9001 then restart</PRE>
2124  <P>In the next example, we have a standard three tier setup with  <P>In the next example, we have a standard three tier setup with
2125  apache, an application server and a back end database server.  apache, an application server and a back end database server.
2126  Dependencies are setup so should oracle be restarted then both  Dependencies are setup so should oracle be restarted then both
2127  apache and the weblogic application server are also restarted.</P>  apache and the weblogic application server are also restarted.</P>
2128  <PRE>  <PRE>
2129   check apache with pidfile /var/run/httpd.pid   check process apache with pidfile /var/run/httpd.pid
2130     start program = &quot;/etc/init.d/httpd start&quot;     start program = &quot;/etc/init.d/httpd start&quot;
2131     stop  program = &quot;/etc/init.d/httpd stop&quot;     stop  program = &quot;/etc/init.d/httpd stop&quot;
2132     depends on weblogic</PRE>     depends on weblogic</PRE>
2133  <PRE>  <PRE>
2134   check weblogic with pidfile /var/run/weblogic.pid   check process weblogic with pidfile /var/run/weblogic.pid
2135     start program = &quot;/etc/init.d/weblogic start&quot;     start program = &quot;/etc/init.d/weblogic start&quot;
2136     stop  program = &quot;/etc/init.d/weblogic stop&quot;     stop  program = &quot;/etc/init.d/weblogic stop&quot;
2137     depends on oracle</PRE>     depends on oracle</PRE>
2138  <PRE>  <PRE>
2139   check oracle with pidfile /var/run/oracle.pid   check process oracle with pidfile /var/run/oracle.pid
2140     start program = &quot;/etc/init.d/oracle start&quot;     start program = &quot;/etc/init.d/oracle start&quot;
2141     stop program  = &quot;/etc/init.d/oracle stop&quot;     stop program  = &quot;/etc/init.d/oracle stop&quot;
2142     port 9001</PRE>     if failed port 9001 then restart</PRE>
2143  <P>Next, we have 2 programs oracle-import and oracle-export that  <P>Next, we have 2 services oracle-import and oracle-export that
2144  need to be restarted if oracle is restarted, but are independent  need to be restarted if oracle is restarted, but are independent
2145  of each other.</P>  of each other.</P>
2146  <PRE>  <PRE>
2147   check oracle with pidfile /var/run/oracle.pid   check process oracle with pidfile /var/run/oracle.pid
2148     start program = &quot;/etc/init.d/oracle start&quot;     start program = &quot;/etc/init.d/oracle start&quot;
2149     stop program  = &quot;/etc/init.d/oracle stop&quot;     stop program  = &quot;/etc/init.d/oracle stop&quot;
2150     port 9001</PRE>     if failed port 9001 then restart</PRE>
2151  <PRE>  <PRE>
2152   check oracle-import with pidfile /var/run/oracle-import.pid   check process oracle-import with pidfile /var/run/oracle-import.pid
2153     start program = &quot;/etc/init.d/oracle-import start&quot;     start program = &quot;/etc/init.d/oracle-import start&quot;
2154     stop  program = &quot;/etc/init.d/oracle-import stop&quot;     stop  program = &quot;/etc/init.d/oracle-import stop&quot;
2155     depends on oracle</PRE>     depends on oracle</PRE>
2156  <PRE>  <PRE>
2157   check oracle-export with pidfile /var/run/oracle-export.pid   check process oracle-export with pidfile /var/run/oracle-export.pid
2158     start program = &quot;/etc/init.d/oracle-export start&quot;     start program = &quot;/etc/init.d/oracle-export start&quot;
2159     stop  program = &quot;/etc/init.d/oracle-export stop&quot;     stop  program = &quot;/etc/init.d/oracle-export stop&quot;
2160     depends on oracle</PRE>     depends on oracle</PRE>
2161  <P>Finally an example with all statements:</P>  <P>Finally an example with all statements:</P>
2162  <PRE>  <PRE>
2163   check apache with pidfile /var/run/httpd.pid   check process apache with pidfile /var/run/httpd.pid
2164     group server     group server
2165     start program = &quot;/etc/init.d/httpd start&quot;     start program = &quot;/etc/init.d/httpd start&quot;
2166     stop program  = &quot;/etc/init.d/httpd stop&quot;     stop program  = &quot;/etc/init.d/httpd stop&quot;
2167     checksum /usr/local/apache/bin/httpd     if failed host www.sol.no port 80  type tcp protocol http
2168      and expect the sum 8f7f419955cefa0b33a2ba316cba3659        then restart
2169     host www.sol.no     port 80  type tcp protocol http     if failed host kvasir.sol.no  port 80  type tcp protocol http
    host kvasir.sol.no  port 80  type tcp protocol http  
2170        and use the request &quot;/login.cgi&quot;        and use the request &quot;/login.cgi&quot;
2171     host shop.sol.no port 443 type tcpssl proto http        then alert
2172     timeout (2,3)     if failed host shop.sol.no port 443 type tcpssl proto http
2173     if cpuusage is greater than 60.0 for 2 cycles then alert        and with timeout 15 seconds
2174     if cpuusage &gt; 80.0 for 5 cycles then restart        then restart
2175     if memkbyte &gt; 100000 then stop     if cpu is greater than 60% for 2 cycles then alert
2176     if timestamp &quot;/usr/local/apache/logs/httpd.pid&quot; &gt; 7 days     if cpu &gt; 80% for 5 cycles then restart
2177         then restart     if mem &gt; 100 MB then stop
    alert foo@bar on { checksum }  
2178     alert bofh@bar with mail-format {from: monit@foo.bar.no}     alert bofh@bar with mail-format {from: monit@foo.bar.no}
2179     every 2 cycles     every 2 cycles
2180     mode active     mode active
2181     depends on weblogic</PRE>     depends on weblogic
2182  <P>Note; only the <STRONG>check-</STRONG> and <STRONG>pidfile statement</STRONG> are mandatory,     depends on httpd.pid
2183       depends on httpd.conf
2184       depends on httpd_bin
2185       depends on datafs
2186       if 3 restarts within 5 cycles then timeout</PRE>
2187    <PRE>
2188     check file httpd.pid with path /usr/local/apache/logs/httpd.pid
2189       group server
2190       if timestamp &gt; 7 days then restart
2191       every 2 cycles
2192       alert bofh@bar with mail-format {from: monit@foo.bar.no}
2193       depends on datafs</PRE>
2194    <PRE>
2195     check file httpd.conf with path /usr/local/apache/conf/httpd.conf
2196       group server
2197       if timestamp was changed then restart
2198       every 2 cycles
2199       alert bofh@bar with mail-format {from: monit@foo.bar.no}
2200       depends on datafs</PRE>
2201    <PRE>
2202     check file httpd_bin with path /usr/local/apache/bin/httpd
2203       group server
2204       if failed checksum and expect the sum
2205         8f7f419955cefa0b33a2ba316cba3659 the unmonitor
2206       if failed permission 755 then unmonitor
2207       if failed uid root then unmonitor
2208       if failed gid root then unmonitor
2209       if size changed then alert
2210       if timestamp changed then alert
2211       every 2 cycles
2212       alert bofh@bar with mail-format {from: monit@foo.bar.no}
2213       alert foo@bar on { checksum, size, timestamp, uid, gid }
2214       depends on datafs</PRE>
2215    <PRE>
2216     check device datafs with path /dev/sdb1
2217       group server
2218       start program  = &quot;/bin/mount /data&quot;
2219       stop program  =  &quot;/bin/umount /data&quot;
2220       if failed permission 660 then unmonitor
2221       if failed uid root then unmonitor
2222       if failed gid disk then unmonitor
2223       if space usage &gt; 80 % then alert
2224       if space usage &gt; 94 % then stop
2225       if inode usage &gt; 80 % then alert
2226       if inode usage &gt; 94 % then stop
2227       alert root@localhost</PRE>
2228    <P>Note; only the <STRONG>check</STRONG> and <STRONG>pidfile statement</STRONG> are mandatory,
2229  the other statements are optional and the order of the optional  the other statements are optional and the order of the optional
2230  statements is not important.</P>  statements is not important.</P>
2231  <P>  <P>
# Line 1335  entries are mode <EM>manual</EM> and con Line 2256  entries are mode <EM>manual</EM> and con
2256   #   #
2257   # local services on every host   # local services on every host
2258   #   #
2259   check heartbeat with pidfile /var/run/heartbeat.pid   check process heartbeat with pidfile /var/run/heartbeat.pid
2260         start program = &quot;/etc/init.d/heartbeat start&quot;         start program = &quot;/etc/init.d/heartbeat start&quot;
2261         stop  program = &quot;/etc/init.d/heartbeat start&quot;         stop  program = &quot;/etc/init.d/heartbeat start&quot;
2262         mode  active         mode  active
2263         alert foo@bar         alert foo@bar
2264         group local</PRE>         group local</PRE>
2265  <PRE>  <PRE>
2266   check postfix with pidfile /var/spool/postfix/pid/master.pid   check process postfix with pidfile /var/spool/postfix/pid/master.pid
2267         start program = &quot;/etc/init.d/postfix start&quot;         start program = &quot;/etc/init.d/postfix start&quot;
2268         stop program  = &quot;/etc/init.d/postfix stop&quot;         stop program  = &quot;/etc/init.d/postfix stop&quot;
2269         mode  active         mode  active
# Line 1353  entries are mode <EM>manual</EM> and con Line 2274  entries are mode <EM>manual</EM> and con
2274   # node1 services   # node1 services
2275   #</PRE>   #</PRE>
2276  <PRE>  <PRE>
2277   check apache with pidfile /var/apache/logs/httpd.pid   check process apache with pidfile /var/apache/logs/httpd.pid
2278         start program = &quot;/etc/init.d/apache start&quot;         start program = &quot;/etc/init.d/apache start&quot;
2279         stop program  = &quot;/etc/init.d/apache stop&quot;         stop program  = &quot;/etc/init.d/apache stop&quot;
2280         depends named         depends named
# Line 1361  entries are mode <EM>manual</EM> and con Line 2282  entries are mode <EM>manual</EM> and con
2282         mode  manual         mode  manual
2283         group node1</PRE>         group node1</PRE>
2284  <PRE>  <PRE>
2285   check named with pidfile /var/tmp/named.pid   check process named with pidfile /var/tmp/named.pid
2286         start program = &quot;/etc/init.d/named start&quot;         start program = &quot;/etc/init.d/named start&quot;
2287         stop program  = &quot;/etc/init.d/named stop&quot;         stop program  = &quot;/etc/init.d/named stop&quot;
2288         alert foo@bar         alert foo@bar
# Line 1372  entries are mode <EM>manual</EM> and con Line 2293  entries are mode <EM>manual</EM> and con
2293   # node2 services   # node2 services
2294   #</PRE>   #</PRE>
2295  <PRE>  <PRE>
2296   check named-slave with pidfile /var/tmp/named-slave.pid   check process named-slave with pidfile /var/tmp/named-slave.pid
2297         start program = &quot;/etc/init.d/named-slave start&quot;         start program = &quot;/etc/init.d/named-slave start&quot;
2298         stop program  = &quot;/etc/init.d/named-slave stop&quot;         stop program  = &quot;/etc/init.d/named-slave stop&quot;
2299         mode  manual         mode  manual
2300         alert foo@bar         alert foo@bar
2301         group node2</PRE>         group node2</PRE>
2302  <PRE>  <PRE>
2303   check squid with pidfile /var/squid/logs/squid.pid   check process squid with pidfile /var/squid/logs/squid.pid
2304         start program = &quot;/etc/init.d/squid start&quot;         start program = &quot;/etc/init.d/squid start&quot;
2305         stop program  = &quot;/etc/init.d/squid stop&quot;         stop program  = &quot;/etc/init.d/squid stop&quot;
2306         depends named-slave         depends named-slave
# Line 1458  specific group per node.</P> Line 2379  specific group per node.</P>
2379  <P><EM>/etc/monit.pid</EM>  <P><EM>/etc/monit.pid</EM>
2380     Lock file to help prevent concurrent runs (root mode,     Lock file to help prevent concurrent runs (root mode,
2381     systems without /var/run).</P>     systems without /var/run).</P>
2382    <P><EM>~/.monit.state</EM>  
2383       monit save its state to this file and utilize
2384       information found in this file to recover from
2385       a crash. This is a binary file and it's content is
2386       only of interest to monit. You may set the location
2387       of this file in the monit control file or by using
2388       the -s switch when monit is started.</P>
2389  <P>  <P>
2390  <HR>  <HR>
2391  <H1><A NAME="signals">SIGNALS</A></H1>  <H1><A NAME="signals">SIGNALS</A></H1>
2392  <P>If a monit daemon is running, SIGUSR1 wakes it up from its sleep  <P>If a monit daemon is running, SIGUSR1 wakes it up from its sleep
2393  phase and forces a poll of all processes. SIGTERM will gracefully  phase and forces a poll of all services. SIGTERM and SIGINT will
2394  terminate a monit daemon. This signal is sent to a monit daemon  gracefully terminate a monit daemon. The SIGTERM signal is sent
2395  if monit is started with the <EM>quit</EM> action argument.</P>  to a monit daemon if monit is started with the <EM>quit</EM> action
2396    argument.</P>
2397  <P>Sending a SIGHUP signal to a running monit daemon will force  <P>Sending a SIGHUP signal to a running monit daemon will force
2398  the daemon to reinitialize itself, specifically it will reread  the daemon to reinitialize itself, specifically it will reread
2399  configuration, close and reopen log files.</P>  configuration, close and reopen log files.</P>

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.17

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26