etc/sr
d0e4b0df
 #!/bin/sh
1eb328e2
 #
03404c52
 # $Id$
 #
 #
1eb328e2
 # 3w-xxxx:      Starts the sip_router process
 #
 # Version:      @(#) /etc/rc.d/init.d/3w-xxxx
 #
 # chkconfig: 2345 20 80
 # description: controls execution of SIP router
8386d432
 # processname: sr
d0e4b0df
 # config: /etc/ser/iptel.cfg
1eb328e2
 
 # Source function library.
 . /etc/rc.d/init.d/functions
 
 # we use a ser symlink -- that allows us to have a different name
 # in process table so that killalls does not start other sers
 # run from somewhere else
 
afe581f8
 BINNAME=sr
1eb328e2
 HM=/home/srouter
afe581f8
 SERDIR=$HM/sip_router
d0e4b0df
 ETC=/etc/ser/iptel.cfg
afe581f8
 PIDFILE=/var/run/sr.pid
 NOTIFY=sr@iptel.org
1eb328e2
 USR=510
 GRP=510
 
afe581f8
 MONIT=/usr/local/bin/monit
 MONITRC=/usr/local/etc/monitrc
 
1eb328e2
 RETVAL=0
 
afe581f8
 BIN=$HM/bin/$BINNAME
1eb328e2
 MYDIR=$HM/core
 CORE=$MYDIR/core
afe581f8
 TMP=/tmp/srcore.$$
 
 ser_start() {
 	if [ -r $BIN -a -r $CORE ] ; then
 		echo "before startup ser core found on `date` at $HOSTNAME" > $TMP
 		echo "----------------------------------" >> $TMP
 		DATE=`date "+%Y-%m-%d--%H-%M"`
 		NEWCORE=$MYDIR/core.$DATE
 		mv $CORE $NEWCORE
 		echo core stored in $NEWCORE >> $TMP
 		gdb $BIN $NEWCORE -x test/bt.gdb -batch >> $TMP
 		chmod a+r $NEWCORE
 		cd $SERDIR; tar czf $MYDIR/ser.$DATE.tgz .
 		mail -s "ser core found" $NOTIFY < $TMP
 		rm -f $TMP
 	fi
 	cd $MYDIR
 	#ulimit -c 1000000
d0e4b0df
 	echo "Starting SIP router: "
afe581f8
 	$BIN -f $ETC -w $MYDIR -P $PIDFILE
 	RETVAL=$?
d0e4b0df
 	echo
 }
 
 ser_stop() {
 	echo "Stopping SIP router: "
 	killproc $BINNAME
 	RETVAL=$?
 	echo
 }
 
 monit_start() {
    echo "Command Monit to start Ser..."
    ${MONIT} -c ${MONITRC} start ser
    RETVAL=$?
    echo
 }
 
 monit_stop() {
    echo "Command Monit to stop Ser..."
    ${MONIT} -c ${MONITRC} stop ser
    RETVAL=$?
    echo
afe581f8
 }
1eb328e2
 
 # See how we were called.
 case "$1" in
afe581f8
   serstart)
 	ser_start
 	;;
   serstop)
d0e4b0df
     ser_stop
afe581f8
 	;;
   serrestart)
d0e4b0df
 	ser_stop
 	echo
 	ser_start
afe581f8
 	;;
1eb328e2
   start)
d0e4b0df
     monit_start
1eb328e2
 	;;
   stop)
d0e4b0df
     monit_stop
1eb328e2
 	;;
   restart)
d0e4b0df
 	monit_stop
 	sleep 1
 	monit_start
1eb328e2
 	;;
   *)
d0e4b0df
 	echo "Usage: $0 {start|stop|restart}"
1eb328e2
 	exit 1
 esac
 
 exit $RETVAL