Browse code

Integrated the core function of sercheck. Added the start and stop of monit. Added the pidfile parameter to ser execution.

Nils Ohlmeier authored on 13/08/2002 05:05:34
Showing 1 changed files
... ...
@@ -15,49 +15,85 @@
15 15
 # Source function library.
16 16
 . /etc/rc.d/init.d/functions
17 17
 
18
-#BIN=sip_router
19
-#ETC=sip_router.cfg
20
-
21 18
 # we use a ser symlink -- that allows us to have a different name
22 19
 # in process table so that killalls does not start other sers
23 20
 # run from somewhere else
24 21
 
25
-BIN=sr
22
+BINNAME=sr
26 23
 HM=/home/srouter
27
-ETC=$HM/sip_router/etc/iptel.cfg
24
+SERDIR=$HM/sip_router
25
+ETC=$SERDIR/etc/iptel.cfg
26
+PIDFILE=/var/run/sr.pid
27
+NOTIFY=sr@iptel.org
28 28
 USR=510
29 29
 GRP=510
30 30
 
31
+MONIT=/usr/local/bin/monit
32
+MONITRC=/usr/local/etc/monitrc
33
+MONITPID=/var/run/monit.pid
34
+
31 35
 RETVAL=0
32 36
 
37
+BIN=$HM/bin/$BINNAME
33 38
 MYDIR=$HM/core
34 39
 CORE=$MYDIR/core
40
+TMP=/tmp/srcore.$$
41
+
42
+ser_start() {
43
+	if [ -r $BIN -a -r $CORE ] ; then
44
+		echo "before startup ser core found on `date` at $HOSTNAME" > $TMP
45
+		echo "----------------------------------" >> $TMP
46
+		DATE=`date "+%Y-%m-%d--%H-%M"`
47
+		NEWCORE=$MYDIR/core.$DATE
48
+		mv $CORE $NEWCORE
49
+		echo core stored in $NEWCORE >> $TMP
50
+		gdb $BIN $NEWCORE -x test/bt.gdb -batch >> $TMP
51
+		chmod a+r $NEWCORE
52
+		cd $SERDIR; tar czf $MYDIR/ser.$DATE.tgz .
53
+		mail -s "ser core found" $NOTIFY < $TMP
54
+		rm -f $TMP
55
+	fi
56
+	cd $MYDIR
57
+	#ulimit -c 1000000
58
+	$BIN -f $ETC -w $MYDIR -P $PIDFILE
59
+	RETVAL=$?
60
+}
35 61
 
36 62
 # See how we were called.
37 63
 case "$1" in
64
+  serstart)
65
+	echo "Starting SIP router only: "
66
+	ser_start
67
+	RETVAL=$?
68
+	echo
69
+	;;
70
+  serstop)
71
+	echo "Stopping SIP router only: "
72
+	killproc $BINNAME
73
+	RETVAL=$?
74
+	echo
75
+	;;
76
+  serrestart)
77
+	$0 serstop
78
+	$0 serstart
79
+	RETVAL=$?
80
+	;;
38 81
   start)
39
-	echo -n "Starting SIP router: "
40
-	cd $MYDIR
41
-#  core timestamping moved to sercheck; -jiri
42
-#	if [ -f $CORE ] ; then
43
-#		chmod a+r $CORE
44
-#		DATE=`date "+%Y-%m-%d--%H-%M"`
45
-#		mv $CORE $CORE.$DATE
46
-#		( cd ../sip_router; tar cf - . ) | gzip > ser.$DATE.tgz
47
-#	fi
48
-	$HM/bin/$BIN -f $ETC -w $MYDIR
49
-	# man setuid: If uid is different from the old effective uid, 
50
-    # the process will be forbidden from eaving core dumps.
51
-	# -> don't set uid, we want to collect core dumps
52
-	# -u $USR -g $GRP 
82
+	echo -n "Starting SIP router and monit: "
83
+	ser_start
53 84
 	RETVAL=$?
85
+	# ser needs some time to listen
86
+	# but monit test on startup so give ser a little time
87
+	sleep 2
88
+	$MONIT -v -c $MONITRC
54 89
 	echo
55 90
 	;;
56 91
   stop)
57
-	echo "Stopping SIP router: "
58
-	killproc $BIN
92
+	echo "Stopping SIP router and monit: "
93
+	killall monit
94
+	killproc $BINNAME
59 95
 	RETVAL=$?
60
-        echo
96
+	echo
61 97
 	;;
62 98
   restart)
63 99
 	$0 stop
... ...
@@ -65,7 +101,9 @@ case "$1" in
65 65
 	RETVAL=$?
66 66
 	;;
67 67
   *)
68
-	echo "Usage: $0 {start|stop|restart}"
68
+	echo "Usage: $0 {start|stop|restart|serstart|serstop|serrestart}"
69
+	echo "  serstart, serstop and serrestart influence only ser."
70
+	echo "  start, stop and restart influence monit and ser."
69 71
 	exit 1
70 72
 esac
71 73