Page 1 of 1

2nd Attempt at Monit

Posted: Sun Jan 23, 2011 6:14 pm
by jamesarbrown
Hi,

Ok so this is version2.... much improved as I now have read the monit manual again, first time in years and realised it has new features (eg works without pid)

The monit package needs inserting into the Gar build

Download the gar and unzip and untar.

Create Folder /gar-minimyth-0.76b2/scripts/utils/monit. In the folder put the following files
checksums

Code: Select all

2772b6f5ad46eb0f73f13e12a26267e1  download/monit-5.2.3.tar.gz
Makefile

Code: Select all

GARNAME = monit
GARVERSION = 5.2.3
CATEGORIES = utils
MASTER_SITES  = http://mmonit.com/monit/dist/
DISTFILES = monit-5.2.3.tar.gz
LICENSE = GPL2

DESCRIPTION = 
define BLURB
endef

DEPENDS = lang/c

CONFIGURE_SCRIPTS = $(WORKSRC)/configure
BUILD_SCRIPTS     = $(WORKSRC)/Makefile
INSTALL_SCRIPTS   = $(WORKSRC)/Makefile

CONFIGURE_ARGS = $(DIRPATHS) --build=$(GARBUILD) --host=$(GARHOST)\
                --without-ssl

include ../../gar.mk
Add to minimyth.conf.mk

Code: Select all

mm_USER_PACKAGES          ?= utils/monit
mm_USER_BIN_LIST          ?= monit
BUILD IT

Conf Directory Files

Now some extra bits needed in the confro directory before booting

confro directory/monitrc

Code: Select all

 check process mythfrontend matching "/usr/bin/mythfrontend*"
   start program = "/usr/bin/mm_command x_start"
   stop program = "/usr/bin/mm_command x_stop"
   if 2 restarts within 2 cycles then exec "/sbin/reboot"

 check process X matching "/usr/bin/X *"
   start program = "/usr/bin/mm_command x_start"
   stop program = "/usr/bin/mm_command x_stop"
   if 2 restarts within 2 cycles then exec "/sbin/reboot"
Add to your minimyth.conf file

Code: Select all

MM_MINIMYTH_FETCH_MINIMYTH_PM='yes'
MM_MONIT_ENABLED='yes'
MM_MONIT_FETCH_MONITRC='yes'
Create the following minimyth.pm file in the conf directory

Code: Select all

package init::minimyth;

use strict;
use warnings;
use threads;

use MiniMyth ();

sub start
{
    my $self     = shift;
    my $minimyth = shift;

    &startMonit($minimyth);

    return 1;
}

sub stop
{
    my $self     = shift;
    my $minimyth = shift;

    return 1;
}

sub startMonit
{
    my $minimyth = shift;

    #Get the monitrc file from the conf directory
    if($minimyth->var_get('MM_MONIT_FETCH_MONITRC') eq 'yes')
    {
        $minimyth->confro_get('monitrc', '/etc/monitrc');
    }

    #If monit is enabled start it - delayed to allow system to startup
    if ($minimyth->var_get('MM_MONIT_ENABLED') eq 'yes')
    {
        if (!-e "/var/run/monit.pid")
        {
            if (!-e "/etc/monitrc")
            {
                $minimyth->message_log('err', "Monit could not start, no monitrc in confro directory");
            } else
            { 
                my $pid = fork();
                if (defined($pid) && $pid==0)
                {
                    my $exit_code = system(qq(sleep 100s;/bin/su -c '/usr/bin/monit -d 15 -p /var/run/monit.pid -l /var/log/monit'));
                    exit $exit_code >> 8;
                }
            }
        }
    }
}
Hope it helps.

James