OpenSER And Monit

monit is a tool for managing and monitoring services on Unix platforms. It can execute a set of actions in error situations. It will be used to detect when OpenSER stops running and will start it again. It can read the OpenSER pid from a file and check from time to time if the process with that pid is running.

Install monit

Download the latest sources from monit web site, compile them locally and install:

cd /usr/local/src
wget http://www.tildeslash.com/monit/dist/monit-4.8.1.tar.gz
tar xvfz monit-4.8.1.tar.gz
cd monit-4.8.1
./configure
make
make install


OpenSER init.d script

The script to starts/stop OpenSER must be placed in '/etc/init.d/openser'.

#!/bin/sh
#
# chkconfig: 2345 20 80
# description: controls execution of OpenSER SIP server
# processname: openser
# config: /usr/local/etc/openser/openser.cfg

# Source function library.
. /etc/rc.d/init.d/functions

# we use a openser symlink -- that allows us to have a different name
# in process table so that killalls does not start other sers
# run from somewhere else

BINNAME=openser
OSRDIR=/usr/local/sbin
OSRWDIR=/var/tmp
ETC=/usr/local/etc/openser/openser.cfg
PIDFILE=/var/run/openser.pid

MONIT=/usr/local/bin/monit
MONITRC=/usr/local/etc/monitrc

RETVAL=0

BIN=$OSRDIR/$BINNAME
CORE=$OSRWDIR/core
TMP=/tmp/osrcore.$$

openser_start() {
	echo "Starting Open SIP Server: "
	$BIN -f $ETC -w $OSRWDIR -P $PIDFILE
	RETVAL=$?
	echo
}

openser_stop() {
	echo "Stopping Open SIP Server: "
	killproc $BINNAME
	RETVAL=$?
	echo
}

monit_start() {
	echo "Command Monit to start OpenSER..."
	${MONIT} -c ${MONITRC} start openser
	RETVAL=$?
	echo
}

monit_stop() {
	echo "Command Monit to stop OpenSER..."
	${MONIT} -c ${MONITRC} stop openser
	RETVAL=$?
	echo
}

# See how we were called.
case "$1" in
	openserstart)
		openser_start
		;;
	openserstop)
		openser_stop
		;;
	openserrestart)
		openser_stop
		echo
		openser_start
		;;
	start)
		monit_start
	;;
	stop)
		monit_stop
	;;
	restart)
		monit_stop
		sleep 1
		monit_start
		;;
	*)
		echo "Usage: $0 {start|stop|restart|openserstart|openserstop|openserrestart}"
		exit 1
esac

exit $RETVAL


Configure monit

The configuration file for monit will be placed in '/usr/local/etc/monitrc'. There are a set of parameters that you can set to monitor your OpenSER instance.

1. Check time - how often to check if OpenSER is running. To check every 60 seconds you must have:

set daemon 60


2. To send email alerts when special situation occurs:

set alert alert@yourdomain.com


3. Monitor OpenSER

check process openser with pidfile /var/run/openser.pid
start program = "/etc/init.d/openser openserstart"
stop program = "/etc/init.d/openser openserstop"
if 3 restarts within 4 cycles then timeout


4. Install monit in inittab to have it running when system starts. Edit '/etc/inittab' and add following line:

mo:2345:respawn:/usr/local/bin/monit -Ic /usr/local/etc/monitrc


Restart inittab:

telinit q


See also:


OpenSER - open source SIP server with TLS support
monit is a tool for managing and monitoring services on Unix platforms. It can execute a set of actions in error situations. It will be used to detect when OpenSER stops running and will start it again. It can read the OpenSER pid from a file and check from time to time if the process with that pid is running.

Install monit

Download the latest sources from monit web site, compile them locally and install:

cd /usr/local/src
wget http://www.tildeslash.com/monit/dist/monit-4.8.1.tar.gz
tar xvfz monit-4.8.1.tar.gz
cd monit-4.8.1
./configure
make
make install


OpenSER init.d script

The script to starts/stop OpenSER must be placed in '/etc/init.d/openser'.

#!/bin/sh
#
# chkconfig: 2345 20 80
# description: controls execution of OpenSER SIP server
# processname: openser
# config: /usr/local/etc/openser/openser.cfg

# Source function library.
. /etc/rc.d/init.d/functions

# we use a openser symlink -- that allows us to have a different name
# in process table so that killalls does not start other sers
# run from somewhere else

BINNAME=openser
OSRDIR=/usr/local/sbin
OSRWDIR=/var/tmp
ETC=/usr/local/etc/openser/openser.cfg
PIDFILE=/var/run/openser.pid

MONIT=/usr/local/bin/monit
MONITRC=/usr/local/etc/monitrc

RETVAL=0

BIN=$OSRDIR/$BINNAME
CORE=$OSRWDIR/core
TMP=/tmp/osrcore.$$

openser_start() {
	echo "Starting Open SIP Server: "
	$BIN -f $ETC -w $OSRWDIR -P $PIDFILE
	RETVAL=$?
	echo
}

openser_stop() {
	echo "Stopping Open SIP Server: "
	killproc $BINNAME
	RETVAL=$?
	echo
}

monit_start() {
	echo "Command Monit to start OpenSER..."
	${MONIT} -c ${MONITRC} start openser
	RETVAL=$?
	echo
}

monit_stop() {
	echo "Command Monit to stop OpenSER..."
	${MONIT} -c ${MONITRC} stop openser
	RETVAL=$?
	echo
}

# See how we were called.
case "$1" in
	openserstart)
		openser_start
		;;
	openserstop)
		openser_stop
		;;
	openserrestart)
		openser_stop
		echo
		openser_start
		;;
	start)
		monit_start
	;;
	stop)
		monit_stop
	;;
	restart)
		monit_stop
		sleep 1
		monit_start
		;;
	*)
		echo "Usage: $0 {start|stop|restart|openserstart|openserstop|openserrestart}"
		exit 1
esac

exit $RETVAL


Configure monit

The configuration file for monit will be placed in '/usr/local/etc/monitrc'. There are a set of parameters that you can set to monitor your OpenSER instance.

1. Check time - how often to check if OpenSER is running. To check every 60 seconds you must have:

set daemon 60


2. To send email alerts when special situation occurs:

set alert alert@yourdomain.com


3. Monitor OpenSER

check process openser with pidfile /var/run/openser.pid
start program = "/etc/init.d/openser openserstart"
stop program = "/etc/init.d/openser openserstop"
if 3 restarts within 4 cycles then timeout


4. Install monit in inittab to have it running when system starts. Edit '/etc/inittab' and add following line:

mo:2345:respawn:/usr/local/bin/monit -Ic /usr/local/etc/monitrc


Restart inittab:

telinit q


See also:


OpenSER - open source SIP server with TLS support
Created by: openser, Last modification: Sun 02 of Jul, 2006 (18:52 UTC)
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+