[OpenSIPS-Devel] [PATCH 1/1] Various cleaus and fixes to the Fedora init-script

Peter Lemenkov lemenkov at gmail.com
Mon Jul 11 16:14:49 CEST 2011


* Proper (according to LSB) return values
* Explicitly set up PID_file and lock-file
* Check for running OpenSIPs before some operations

Signed-off-by: Peter Lemenkov <lemenkov at gmail.com>
---
 packaging/fedora/opensips.init |   39 ++++++++++++++++++++++++++++++---------
 1 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/packaging/fedora/opensips.init b/packaging/fedora/opensips.init
index 40adb88..685d1ef 100644
--- a/packaging/fedora/opensips.init
+++ b/packaging/fedora/opensips.init
@@ -20,28 +20,49 @@
 # Source function library.
 . /etc/rc.d/init.d/functions
 
-oser=/usr/sbin/opensips
 prog=opensips
+oser=/usr/sbin/$prog
+pidfile="/var/run/$prog.pid"
+lockfile="/var/lock/subsys/$prog"
+configfile="/etc/$prog/$prog.cfg"
+OPTIONS=""
+
 RETVAL=0
 
 [ -f /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
 
 start() {
 	echo -n $"Starting $prog: "
+
+	# check whether OpenSIPs was already started
+	if status $prog > /dev/null 2>&1 ; then
+		echo -n "already running" && warning && echo
+		return 0
+	fi
+
 	# there is something at end of this output which is needed to
 	# report proper [ OK ] status in Fedora scripts
-	daemon $oser $OPTIONS 2>/dev/null | tail -1
+	daemon $oser -P $pidfile -f $configfile $OPTIONS 2>/dev/null | tail -1
 	RETVAL=$?
 	echo
-	[ $RETVAL = 0 ] && touch /var/lock/subsys/$prog
+	[ $RETVAL = 0 ] && touch $lockfile
+	return $RETVAL
 }
 
 stop() {
 	echo -n $"Stopping $prog: "
-	killproc $oser
+
+	# check whether OpenSIPs is running
+	if ! status $prog > /dev/null 2>&1 ; then
+		echo -n "not running" && warning && echo
+		return 0
+	fi
+
+	killproc $prog 2> /dev/null
 	RETVAL=$?
 	echo
-	[ $RETVAL = 0 ] && rm -f /var/lock/subsys/$prog /var/run/$prog.pid
+	[ $RETVAL = 0 ] && rm -f $lockfile $pidfile
+	return $RETVAL
 }
 
 # See how we were called.
@@ -53,22 +74,22 @@ case "$1" in
 		stop
 		;;
 	status)
-		status $oser
+		status $prog
 		RETVAL=$?
 		;;
 	restart|reload)
 		stop
 		start
 		;;
-	condrestart)
-		if [ -f /var/run/opensips.pid ] ; then
+	condrestart|try-restart)
+		if [ -f $pidfile ] ; then
 			stop
 			start
 		fi
 		;;
 	*)
 		echo $"Usage: $prog {start|stop|reload|restart|condrestart|status|help}"
-		exit 1
+		RETVAL=2
 esac
 
 exit $RETVAL
-- 
1.7.6




More information about the Devel mailing list