<rdf:RDF
    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
    xmlns:s='http://snipsnap.org/rdf/snip-schema#'
    xml:base='http://bliki.rimuhosting.com/rdf'>
    <s:Snip rdf:about='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/miscapplications/monit+service+monitoring'
         s:cUser='john'
         s:oUser=''
         s:mUser='alex'>
        <s:name>knowledgebase/linux/miscapplications/monit service monitoring</s:name>
        <s:content>{link:Monit|http://www.tildeslash.com/monit/} is an application service monitor.  It can tell you if your MySQL or Apache server has crashed, and even give it a swift kick to get it up and going again.&#xD;&#xA;&#xD;&#xA;Compared to other service monitors I&apos;ve looked at, Monit has good {link:documentation|http://www.tildeslash.com/monit/doc/}, and a straightforward configuration.&#xD;&#xA;&#xD;&#xA;It&apos;s available as a Debian package and there is an RPM here:&#xD;&#xA;http://dag.wieers.com/rpm/packages/monit/&#xD;&#xA;&#xD;&#xA;On Debian, it won&apos;t start automatically after installing:&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;apt-get install monit&#xD;&#xA;Reading \package lists... Done&#xD;&#xA;Building dependency tree... Done&#xD;&#xA;The following NEW packages will be installed:&#xD;&#xA;  monit&#xD;&#xA;0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.&#xD;&#xA;Need to get 0B/255kB of archives.&#xD;&#xA;After unpacking 680kB of additional disk space will be used.&#xD;&#xA;Selecting previously deselected \package monit.&#xD;&#xA;(Reading database ... 58858 files and directories currently installed.)&#xD;&#xA;Unpacking monit (from .../monit_1%3a4.8.1-2.1_i386.deb) ...&#xD;&#xA;Setting up monit (4.8.1-2.1) ...&#xD;&#xA;Starting daemon monitor: monit won&apos;t be started/stopped&#xD;&#xA;        unless it it&apos;s configured&#xD;&#xA;        please configure monit and then edit /etc/\default/monit&#xD;&#xA;        and set the \&quot;startup\&quot; variable to 1 in order to allow &#xD;&#xA;        monit to start&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;In /usr/share/doc/monit/README.Debian, your find some information about creating a monit_delay script to prevent monit from restarting services that are slow to come up on reboot.  &#xD;&#xA;&#xD;&#xA;Now all you need to do is go uncomment some things in the configuration file.  You&apos;ll find that in /etc/monit/monitrc, or if you use the RPM, it&apos;s /etc/monit.conf&#xD;&#xA;&#xD;&#xA;There are many options for configuring monit, here is what I uncommented to get a simple configuration working:&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;set daemon  120&#xD;&#xA;set logfile syslog facility log_daemon&#xD;&#xA;set mailserver localhost&#xD;&#xA;set alert root@localhost&#xD;&#xA;set httpd port 2812 and&#xD;&#xA;use address localhost  # only accept connection from localhost&#xD;&#xA;allow localhost        # allow localhost to connect to the server and&#xD;&#xA;allow admin:stR0Ngpsswd       # require user &apos;admin&apos; with password &apos;monit&apos;&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;Instead of putting services in this same file, put them in /etc/monit.d, that way it&apos;s easy to turn off/on monitoring for a particular service.  &#xD;&#xA;&#xD;&#xA;1 Restart Apache&#xD;&#xA;&#xD;&#xA;For testing Apache&apos;s status, it&apos;s standard practice to create an empty file or &apos;token&apos; for Monit to request.   &#xD;&#xA;&#xD;&#xA;On Debian&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;mkdir /\var/www/monit/&#xD;&#xA;touch /\var/www/monit/token&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;Paste this in your Apache configuration:&#xD;&#xA;{code}&#xD;&#xA;SetEnvIf        Request_URI \&quot;^\/monit\/token$\&quot; dontlog&#xD;&#xA;CustomLog       logs/access.log common env=!dontlog&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;Then paste this in /etc/monit.d/apache.conf&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;start program = \&quot;/etc/init.d/apache2 start\&quot;&#xD;&#xA;stop  program = \&quot;/etc/init.d/apache2 stop\&quot;&#xD;&#xA;      \if failed host 127.0.0.1 port 80 &#xD;&#xA;              protocol HTTP request /monit/token then restart&#xD;&#xA;      \if 5 restarts within 5 cycles then timeout&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;Then edit /etc/default/monit&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;# You must set \this variable \for monit to start&#xD;&#xA;startup=1&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;Startup monit&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;/etc/init.d/monit start&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;check that it&apos;s running and then for fun, lets stop apache:&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;ps aux | grep monit &#xD;&#xA;root     11583  0.0  0.7  20400  1248 ?        Sl   04:20   0:00 /usr/sbin/monit -d 180 -c /etc/monit/monitrc -s /var/lib/monit/monit.state&#xD;&#xA;/etc/init.d/apache2 stop&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;In syslog you&apos;ll see something like this:&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;Jun 18 04:32:41 rimu monit[11583]: HTTP error: Server returned status 404 &#xD;&#xA;Jun 18 04:32:41 rimu monit[11583]: &apos;apache2&apos; failed protocol test [HTTP] at INET[127.0.0.1:80] via TCP &#xD;&#xA;Jun 18 04:32:41 rimu monit[11583]: &apos;apache2&apos; trying to restart &#xD;&#xA;Jun 18 04:32:41 rimu monit[11583]: &apos;apache2&apos; stop: /etc/init.d/apache2 &#xD;&#xA;Jun 18 04:32:42 rimu monit[11583]: &apos;apache2&apos; start: /etc/init.d/apache2 &#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;You can find many other configuration examples for MySQL, Mongrel and other popular applications, just google them up.  &#xD;&#xA;&#xD;&#xA;1 watch nginx&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;check process nginx with pidfile /var/run/nginx.pid&#xD;&#xA;  start program = &quot;/etc/init.d/nginx start&quot;&#xD;&#xA;  stop program = &quot;/etc/init.d/nginx stop&quot;&#xD;&#xA;  if failed port 80 protocol HTTP request / then restart&#xD;&#xA;  if 5 restarts with 5 cycles then timeout&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;1 watch mongrels&#xD;&#xA;&#xD;&#xA;http://www.igvita.com/blog/2006/11/07/monit-makes-mongrel-play-nice/&#xD;&#xA;&#xD;&#xA;http://software.pmade.com/blogs/ramblings/2006/12/27/mongrel-cluster-and-monit&#xD;&#xA;&#xD;&#xA;http://rubyforge.org/pipermail/mongrel-users/2006-September/001359.html&#xD;&#xA;&#xD;&#xA;1 watch a VirtualHost or remote URL&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;check host arbitrary_name with address real_url&#xD;&#xA;  if failed port 80 proto http then alert&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;See the man page for more examples.</s:content>
        <s:mTime>2007-12-05 23:21:39.0</s:mTime>
        <s:cTime>2007-06-18 16:57:25.0</s:cTime>
        <s:comments
             rdf:type='http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag'/>
        <s:snipLinks>
            <rdf:Bag>
                <rdf:li rdf:resource='#snipsnap-search'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux'/>
                <rdf:li rdf:resource='#knowledgebase'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/miscapplications'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/rimuhosting/load balancing and failover'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/mail/dkfilter setup'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/miscapplications/ruby on rails'/>
                <rdf:li rdf:resource='#john'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/misc/ajax autocomplete'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/mail/postfix with amavis and mysql'/>
                <rdf:li rdf:resource='#jetty'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/miscapplications/rpm based php5.1 install'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/mail/postfixadmin on RHEL4'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/mail/moving imap folders between hosts'/>
                <rdf:li rdf:resource='#monit'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/miscapplications/Build php 5.1.6 rpm on RHEL4'/>
                <rdf:li rdf:resource='#snipsnap-index'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/rimuhosting/rimuhosting ssh access'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/java/accessing postgres via jdbc'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/Security/Responding to attacks using fail2ban'/>
            </rdf:Bag>
        </s:snipLinks>
        <s:attachments
             rdf:type='http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag'/>
    </s:Snip>
</rdf:RDF>
