examples/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
5d1a75a6
 # config: /etc/sip-router/iptel.cfg
1eb328e2
 
 # Source function library.
 . /etc/rc.d/init.d/functions
 
5d1a75a6
 # we use a sip-router symlink -- that allows us to have a different name
 # in process table so that killalls does not start other sip-routers
1eb328e2
 # run from somewhere else
 
afe581f8
 BINNAME=sr
1eb328e2
 HM=/home/srouter
afe581f8
 SERDIR=$HM/sip_router
5d1a75a6
 ETC=/etc/sip-router/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.$$
 
83d39ae5
 sip_router_start() {
afe581f8
 	if [ -r $BIN -a -r $CORE ] ; then
83d39ae5
 		echo "before startup sip-router core found on `date` at `hostname`" > $TMP
afe581f8
 		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
5d1a75a6
 		cd $SERDIR; tar czf $MYDIR/sip-router.$DATE.tgz .
 		mail -s "sip-router core found" $NOTIFY < $TMP
afe581f8
 		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
 }
 
83d39ae5
 sip_router_stop() {
d0e4b0df
 	echo "Stopping SIP router: "
 	killproc $BINNAME
 	RETVAL=$?
 	echo
 }
 
 monit_start() {
    echo "Command Monit to start Ser..."
5d1a75a6
    ${MONIT} -c ${MONITRC} start sip-router
d0e4b0df
    RETVAL=$?
    echo
 }
 
 monit_stop() {
    echo "Command Monit to stop Ser..."
5d1a75a6
    ${MONIT} -c ${MONITRC} stop sip-router
d0e4b0df
    RETVAL=$?
    echo
afe581f8
 }
1eb328e2
 
 # See how we were called.
 case "$1" in
afe581f8
   serstart)
83d39ae5
 	sip_router_start
afe581f8
 	;;
5d1a75a6
   sip-routerstop)
83d39ae5
     sip_router_stop
afe581f8
 	;;
5d1a75a6
   sip-routerrestart)
83d39ae5
 	sip_router_stop
d0e4b0df
 	echo
83d39ae5
 	sip_router_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