From 043c2982938f1ee15c3d809b706788c09327bf3a Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 28 Feb 2011 14:36:40 -0800 Subject: [PATCH] Removed dependency on LSB - script should now work on generic UNIX and Linux distros without LSB --- init.d/guacd.in | 49 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/init.d/guacd.in b/init.d/guacd.in index e1a8e7d..69841e9 100644 --- a/init.d/guacd.in +++ b/init.d/guacd.in @@ -49,17 +49,37 @@ # Description: The Guacamole proxy daemon, required to translate remote desktop protocols into the text-based Guacamole protocol used by the JavaScript application. ### END INIT INFO -# Source function library. -. /lib/lsb/init-functions - prog="guacd" exec="@sbindir@/$prog" pidfile="/var/run/$prog.pid" +# Returns PID of currently running process, if any +getpid() { + + if [ -f "$pidfile" ] + then + + read PID < "$pidfile" + + # If pidfile contains PID and PID is valid + if [ -n "$PID" ] && ps "$PID" > /dev/null 2>&1 + then + echo "$PID" + return 0 + fi + + fi + + # pidfile/pid not found, or process is dead + return 1 + +} + start() { [ -x $exec ] || exit 5 echo -n "Starting $prog: " - start_daemon -p "$pidfile" $exec -p "$pidfile" + + getpid > /dev/null || $exec -p "$pidfile" retval=$? case "$retval" in @@ -76,24 +96,31 @@ start() { stop() { echo -n "Stopping $prog: " - killproc -p "$pidfile" $prog + + PID=`getpid` retval=$? case "$retval" in 0) - echo "SUCCESS" + if kill $PID > /dev/null 2>&1 + then + echo "SUCCESS" + return 0 + fi + + echo "FAIL" + return 1 ;; *) - echo "FAIL" + echo "SUCCESS (not running)" + return 0 ;; esac - return $retval } restart() { - stop - start + stop && start } force_reload() { @@ -102,7 +129,7 @@ force_reload() { status() { - PID=`pidofproc -p "$pidfile" $prog` + PID=`getpid` retval=$? case "$retval" in -- 1.7.10.4