Author: Peter Eisentraut <petere@debian.org>
Description: init.d status support
Origin: https://bugs.debian.org/528689, https://bugs.debian.org/709163
Last-Update: 2014-09-23

Index: memcached-1.4.20/scripts/memcached-init
===================================================================
--- memcached-1.4.20.orig/scripts/memcached-init
+++ memcached-1.4.20/scripts/memcached-init
@@ -1,14 +1,14 @@
 #! /bin/bash
 ### BEGIN INIT INFO
-# Provides:          memcached
-# Required-Start:    $syslog
-# Required-Stop:     $syslog
-# Should-Start:        $local_fs
-# Should-Stop:        $local_fs
-# Default-Start:     2 3 4 5
-# Default-Stop:      0 1 6
-# Short-Description:    memcached - Memory caching daemon
-# Description:        memcached - Memory caching daemon
+# Provides:            memcached
+# Required-Start:      $remote_fs $syslog
+# Required-Stop:       $remote_fs $syslog
+# Should-Start:                $local_fs
+# Should-Stop:         $local_fs
+# Default-Start:       2 3 4 5
+# Default-Stop:                0 1 6
+# Short-Description:   Start memcached daemon
+# Description:         Start up memcached, a high-performance memory caching daemon
 ### END INIT INFO
 
 # Usage:
@@ -35,6 +35,13 @@ test -x $DAEMONBOOTSTRAP || exit 0
 
 set -e
 
+. /lib/lsb/init-functions
+
+# Edit /etc/default/memcached to change this.
+ENABLE_MEMCACHED=no
+test -r /etc/default/memcached && . /etc/default/memcached
+
+
 FILES=(/etc/memcached_*.conf)
 # check for alternative config schema
 if [ -r "${FILES[0]}" ]; then
@@ -68,44 +75,65 @@ else
   CONFIGS=(memcached)
 fi;
 
+er_or=0
 CONFIG_NUM=${#CONFIGS[@]}
 for ((i=0; i < $CONFIG_NUM; i++)); do
   NAME=${CONFIGS[${i}]}
   PIDFILE="/var/run/${NAME}.pid"
 
 case "$1" in
-    start)
-        echo -n "Starting $DESC: "
-        start-stop-daemon --start --quiet --exec "$DAEMONBOOTSTRAP" -- /etc/${NAME}.conf $PIDFILE
-        echo "$NAME."
-        ;;
-    stop)
-        echo -n "Stopping $DESC: "
-        start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON
-        echo "$NAME."
-        rm -f $PIDFILE
-        ;;
-
-    restart|force-reload)
-    #
-    #   If the "reload" option is implemented, move the "force-reload"
-    #   option to the "reload" entry above. If not, "force-reload" is
-    #   just the same as "restart".
-    #
-        echo -n "Restarting $DESC: "
-        start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
-        rm -f $PIDFILE
-        sleep 1
-        start-stop-daemon --start --quiet --exec "$DAEMONBOOTSTRAP" -- /etc/${NAME}.conf $PIDFILE
-        echo "$NAME."
-        ;;
-    *)
-        N=/etc/init.d/$NAME
-    # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
-        echo "Usage: $N {start|stop|restart|force-reload}" >&2
-        exit 1
-        ;;
+  start)
+       echo -n "Starting $DESC: "
+       if [ $ENABLE_MEMCACHED = yes ]; then
+            start-stop-daemon --start --quiet --exec "$DAEMONBOOTSTRAP" -- /etc/${NAME}.conf $PIDFILE
+            echo "$NAME."
+       else
+            echo "$NAME disabled in /etc/default/memcached."
+       fi
+       ;;
+  stop)
+       echo -n "Stopping $DESC: "
+       start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON
+       echo "$NAME."
+       rm -f $PIDFILE
+       ;;
+
+  restart|force-reload)
+       #
+       #       If the "reload" option is implemented, move the "force-reload"
+       #       option to the "reload" entry above. If not, "force-reload" is
+       #       just the same as "restart".
+       #
+       echo -n "Restarting $DESC: "
+       start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
+       rm -f $PIDFILE
+       if [ $ENABLE_MEMCACHED = yes ]; then
+       		sleep 1
+       		start-stop-daemon --start --quiet --exec "$DAEMONBOOTSTRAP" -- /etc/${NAME}.conf $PIDFILE
+       		echo "$NAME."
+       else
+            echo "$NAME disabled in /etc/default/memcached."
+       fi
+       ;;
+  status)
+       status_of_proc -p $PIDFILE $DAEMON $NAME
+       returnvalue=$(echo $?)
+       if [ "$returnvalue" -ne "0" ]
+       then
+            er_or=$(expr $er_or \+ 1)
+       fi
+       ;;
+  *)
+	N=/etc/init.d/$NAME
+	echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
+	exit 1
+	;;
 esac
 done;
 
-exit 0
+if [ "$er_or" -ne "0" ]
+then
+	exit 2
+else
+	exit 0
+fi
