[Debian-ha-commits] [pcs] 03/03: Update maintainer provided pcsd init script

Richard Winters devrik-guest at moszumanska.debian.org
Wed May 6 01:03:23 UTC 2015


This is an automated email from the git hooks/post-receive script.

devrik-guest pushed a commit to branch master
in repository pcs.

commit a4d30e3c9767f7906ab010ade4ba1c7c165d3bb4
Author: Richard B Winters <rik at mmogp.com>
Date:   Tue May 5 20:54:27 2015 -0400

    Update maintainer provided pcsd init script
    
     - Recreated the init script so it works properly for
       persistent scripts
    
    Change-Id: Ie9abd485469584b3435e375da1a75ee1b999a7a6
    Signed-off-by: Richard B Winters <rik at mmogp.com>
---
 debian/pcsd.init | 150 +++++++++++++++++++++++++++++++------------------------
 1 file changed, 85 insertions(+), 65 deletions(-)

diff --git a/debian/pcsd.init b/debian/pcsd.init
index ea54f94..68390c4 100644
--- a/debian/pcsd.init
+++ b/debian/pcsd.init
@@ -24,11 +24,13 @@ PARENT_NAME=pcs
 NAME=pcsd
 EXEC=ruby
 SUB_EXEC=/usr/share/pcsd/ssl.rb
+DAEMON_USER=root
 DAEMON=/usr/bin/ruby
-DAEMON_ARGS="-I/usr/share/pcsd /usr/share/pcsd/ssl.rb"
-RUN_DIR=/var/lib/pcsd
+DAEMON_ARGS="-C/var/lib/pcsd -I/usr/share/pcsd -- /usr/share/pcsd/ssl.rb"
 PIDFILE=/var/run/$NAME.pid
 SCRIPTNAME=/etc/init.d/$NAME
+LOGFILE=/var/log/$NAME/$NAME.log
+SLEEP_DURATION=2
 
 # Exit if ruby is not installed
 [ -x $(which $EXEC) ] || echo "$EXEC was not found. Is it installed?"
@@ -40,83 +42,101 @@ SCRIPTNAME=/etc/init.d/$NAME
 # Source lsb init functions
 . /lib/lsb/init-functions
 
-do_start() 
+is_running()
 {
-    # Return
-    # 0 if daemon has been started
-    # 1 if daemon was already running
-    # 2 if daemon could not be started
-    start-stop-daemon --start --quiet --chdir $RUN_DIR --test --exec $DAEMON -- test \
-      ||  return 1
-    start-stop-daemon --start --quiet --chdir $RUN_DIR --exec $DAEMON -- $DAEMON_ARGS \
-      || return 2
-    # Add code here, if necessary, that waits for the process to be ready
-    # to handle requests from services started subsequently which depend
-    # on this one.  As a last resort, sleep for some time.
-    pidof pcsd > $PIDFILE
+  # Test whether pid file exists or not
+  test -f $PIDFILE || return 1
+
+  # Test whether process is running or not
+  read PID < "$PIDFILE"
+  ps -p $PID >/dev/null 2>&1 || return 1
+
+  # Is running
+  return 0
 }
 
-do_stop()
+root_only()
 {
-    # Return
-    # 0 if daemon has been stopped
-    # 1 if daemon was already stopped
-    # 2 if daemon could not be stopped
-    # other if a failure occurred
-    start-stop-daemon --stop --quiet --retry forever/QUIT/1 --pidfile $PIDFILE
-    RETVAL="$?"
-    [ "$RETVAL" = 2 ] && return 2
-    # Many daemons don't delete their pidfiles when they exit.
-    rm -f $PIDFILE
-    return "$RETVAL"
+  if [ "$(id -u)" != "0" ]; then
+    echo "Only root should run this operation"
+    exit 1
+  fi
 }
 
+run()
+{
+  if is_running; then
+    PID="$(cat $PIDFILE)"
+    echo "Daemon is already running as PID $PID"
+    return 1
+  fi
+
+  nohup $DAEMON $DAEMON_ARGS > /dev/null 2>&1
+  echo $! > $PIDFILE
+  read PID < "$PIDFILE"
 
+  echo "PID is $PID"
+
+  sleep $SLEEP_DURATION
+  if ! is_running; then
+    echo "Daemon died immediately after starting. Please check your logs and configurations."
+    return 1
+  fi
+
+  echo "Daemon is running as PID $PID"
+  return 0
+}
+
+stop()
+{
+  if is_running; then
+    read PID < "$PIDFILE"
+    kill -9 $PID
+  fi
+
+  sleep $SLEEP_DURATION
+  if is_running; then
+    while is_running; do
+      echo "waiting for daemon to die (PID $PID)"
+      sleep $SLEEP_DURATION
+    done
+  fi
+
+  # Be sure to remove the pid file
+  rm -f "$PIDFILE"
+  return 0
+}
 
 case "$1" in
   start)
-	log_daemon_msg "Starting $DESC" "$NAME"
-	do_start
-	case "$?" in
-		0|1) log_end_msg 0 ;;
-		2) log_end_msg 1 ;;
-	esac
-	;;
+    root_only
+    log_daemon_msg "Starting $DESC"  "$NAME"
+    run
+    log_end_msg $?
+    ;;
   stop)
-	log_daemon_msg "Stopping $DESC" "$NAME"
-	do_stop
-	case "$?" in
-		0|1) log_end_msg 0 ;;
-		2) log_end_msg 1 ;;
-	esac
-	;;
+    root_only
+    log_daemon_msg "Stopping $DESC" "$NAME"
+    stop
+    log_end_msg $?
+    ;;
   restart|force-reload)
-	log_daemon_msg "Restarting $DESC" "$NAME"
-	do_stop
-	case "$?" in
-	  0|1)
-		do_start
-		case "$?" in
-			0) log_end_msg 0 ;;
-			1) log_end_msg 1 ;; # Old process is still running
-			*) log_end_msg 1 ;; # Failed to start
-		esac
-		;;
-	  *)
-	  	# Failed to stop
-		log_end_msg 1
-		;;
-	esac
-	;;
+    log_daemon_msg "Restarting $DESC" "$NAME"
+    root_only
+    $0 stop && $0 start
+    ;;
   status|monitor)
-	status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
-	;;
+    status_of_proc \
+      -p "$PIDFILE" \
+      "$SUB_EXEC" \
+      "$NAME" \
+      && exit 0 \
+      || exit $?
+    ;;
   *)
-	#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
-	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
-	exit 3
-	;;
+    echo "Usage: $0 {start|stop|restart|reload|force-reload|status|monitor}"
+    exit 1
+  ;;
 esac
 
 :
-

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-ha/pcs.git



More information about the Debian-HA-Commits mailing list