# app-admin/monit init script broken?[SOLVED]

## upengan78

Hi,

I installed app-admin/monit yesterday with some configuration for apache2 and smbs/nmbd.

Basically used http://en.gentoo-wiki.com/wiki/Monit to start and configure.

When I use /etc/init/monit script to start monit it returns to bash with (!!) instead of OK which suggsts that process did not start. ps -ef | grep monit also does not show monit process.

Here is the init script :

```

#!/sbin/runscript

# Copyright 1999-2004 Gentoo Foundation

# Distributed under the terms of the GNU General Public License, v2 or later

# $Header: /var/cvsroot/gentoo-x86/app-admin/monit/files/monit.initd-5.0,v 1.1 2008/08/29 20:13:37 caleb Exp $

opts="${opts} reload"

depend() {

   use net

}

start() {

   ebegin "Starting monit"

   start-stop-daemon --start --quiet --exec /usr/bin/monit >/dev/null 2>&1

   eend $?

}

stop() {

   ebegin "Stopping monit"

   start-stop-daemon --stop --quiet --exec /usr/bin/monit

   eend $?

}

reload() {

   ebegin "Reloading monit"

   /usr/bin/monit -c /etc/monitrc reload >/dev/null 2>&1

   eend $?

}
```

/etc/init.d/monit start

```
 * Starting monit ...

Starting /usr/bin/monit...                                                                                                                            [ !! ]
```

I wonder what's wrong with init script. If I start monit manually then it works fine, See below,

/usr/bin/monit -d 120 -c /etc/monitrc -l /var/log/monit.log

```
Starting monit daemon with http interface at [localhost:2812]

```

ps -ef | grep monit

```
root     17780     1  0 11:21 ?        00:00:00 /usr/bin/monit -d 120 -c /etc/monitrc -l /var/log/monit.log

root     17785 15473  0 11:21 pts/5    00:00:00 grep --colour=auto monit

```

Any idea? Does it make sense to report this issue as a bug?

Thanks.Last edited by upengan78 on Thu Jan 06, 2011 8:33 pm; edited 1 time in total

----------

## Mousee

Did you setup /etc/monitrc to monitor anything? Without a working *and* valid configuration to function from, the init script will indeed fail to start Monit.

----------

## upengan78

Yes I have configured /etc/monitrc per wiki link provided in my first post and it works just fine when monit is started manually. I even see that when I stop apache2 process, monit detects and starts apache2 again which is awsome. I do see the webinterface also -> h**p://localhost:2812/

now the  only problem is monit init script does not start monit process. Nor can it stop the manually started monit process.

If must I can provide my /etc/monitrc aswell.

Thank you for helping!

EDIT : 

strace /etc/init.d/monit start ->> http://pastebin.ca/2039765

app-admin/monit : Installed versions:  5.1.1

----------

## upengan78

OK, I unmasked  version 5.2.2 , found that init script is same on old and newer version. That made me feel some config was missing from /etc/monitrc which the startup script is very particular about may be.

I decided to uncomment default values from the /etc/monitrc. After I uncommented below 2 lines, /etc/init.d/monit start worked fine

```

set daemon  120           # check services at 2-minute intervals

set logfile /var/log/monit.log             
```

I hope that stop/reload will work just fine.

Wonder why /etc/init.d/monit in gentoo is different than that is provided with monit-tar.gz (../contrib/rc.monit )

----------

## Mousee

Yeah sorry - I suppose I should have been more precise to say that, should the config file have *anything at all* that doesn't produce the right results for the init script to proceed, it'll puke in the way you've seen. I had the same issue when I first set it up (following the same wiki page) and I ended up just creating a very minimal config to see if that fixed it and then went from there.

I'll try to figure out some decent 'language" to put into the wiki that specifies this behavior a little more so that other users don't get equally confused.

As to the difference in init scripts functioning differently - Gentoo likely uses a different rc system than the one the monit init script was designed for. I haven't ever looked at the original monit one so I'm not sure otherwise.

----------

## upengan78

Thank you Mousee. 

I hope I can save your time by posting the original rc.monit script in contrib folder. Here it is,

```

cat rc.monit 

#! /bin/sh

#

# monit         Monitor Unix systems

#

# Author:   Clinton Work,   <work@scripty.com>

#

# chkconfig:    2345 98 02

# description:  Monit is a utility for managing and monitoring processes,

#               files, directories and filesystems on a Unix system. 

# processname:  monit

# pidfile:      /var/run/monit.pid

# config:       /etc/monitrc

# Source function library.

. /etc/rc.d/init.d/functions

# Source networking configuration.

. /etc/sysconfig/network

MONIT=/usr/bin/monit

# Source monit configuration.

if [ -f /etc/sysconfig/monit ] ; then

        . /etc/sysconfig/monit

fi

[ -f $MONIT ] || exit 0

RETVAL=0

# See how we were called.

case "$1" in

  start)

        echo -n "Starting monit: "

        daemon $NICELEVEL $MONIT

        RETVAL=$?

        echo

        [ $RETVAL = 0 ] && touch /var/lock/subsys/monit

        ;;

  stop)

        echo -n "Stopping monit: "

        killproc monit

        RETVAL=$?

        echo

        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/monit

        ;;

  restart)

     $0 stop

   $0 start

   RETVAL=$?

   ;;

  condrestart)

       [ -e /var/lock/subsys/monit ] && $0 restart

       ;;

  status)

        status monit

   RETVAL=$?

   ;;

  *)

   echo "Usage: $0 {start|stop|restart|condrestart|status}"

   exit 1

esac

exit $RETVAL
```

You have a great day.

----------

