From 9636f5b16c1847bc94d42ca6ac948c680bd55f2e Mon Sep 17 00:00:00 2001 From: Kaushik BV Date: Fri, 20 Jan 2012 11:54:21 +0530 Subject: extras: create PID file for glusterd when started from init scripts thanks to Jaroslav Pulchart (jaroslav.pulchart@centrum.cz) for the patch Change-Id: Id07bf50536c8638f790f06e6e5994f85555c3978 BUG: 771221 Signed-off-by: Kaushik BV Reviewed-on: http://review.gluster.com/2668 Tested-by: Gluster Build System Reviewed-by: Kaleb KEITHLEY Reviewed-by: Vijay Bellur --- extras/init.d/glusterd-Redhat.in | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/extras/init.d/glusterd-Redhat.in b/extras/init.d/glusterd-Redhat.in index 01a3009470e..cf9d390f0cb 100755 --- a/extras/init.d/glusterd-Redhat.in +++ b/extras/init.d/glusterd-Redhat.in @@ -8,28 +8,46 @@ . /etc/rc.d/init.d/functions BASE=glusterd +PIDFILE=/var/run/$BASE.pid +PID=`test -f $PIDFILE && cat $PIDFILE` GLUSTERFSD=glusterfsd GLUSTERFS=glusterfs GLUSTERD_BIN=@prefix@/sbin/$BASE -GLUSTERD_OPTS="" +GLUSTERD_OPTS="--pid-file=$PIDFILE" GLUSTERD="$GLUSTERD_BIN $GLUSTERD_OPTS" RETVAL=0 # Start the service $BASE start() { - echo -n $"Starting $BASE:" - daemon $GLUSTERD - RETVAL=$? - echo - [ $RETVAL -ne 0 ] && exit $RETVAL + pidofproc -p $PIDFILE $GLUSTERD_BIN &> /dev/null + status=$? + if [ $status -eq 0 ]; then + echo "glusterd service is already running with pid $PID" + exit 1 + else + echo -n $"Starting $BASE:" + daemon $GLUSTERD + RETVAL=$? + echo + [ $RETVAL -ne 0 ] && exit $RETVAL + fi + } # Stop the service $BASE stop() { echo -n $"Stopping $BASE:" - killproc $BASE + pidofproc -p $PIDFILE $GLUSTERD_BIN &> /dev/null + status=$? + if [ $status -eq 0 ]; then + killproc -p $PIDFILE $BASE + [ -w $PIDFILE ] && rm -f $PIDFILE + else + killproc $BASE + fi + echo pidof -c -o %PPID -x $GLUSTERFSD &> /dev/null [ $? -eq 0 ] && killproc $GLUSTERFSD &> /dev/null -- cgit