init scripts: Fix bug with writing PID files
[hcoop/domtool2.git] / scripts / domtool-slave
index 2d5588f..5392bea 100755 (executable)
@@ -1,9 +1,10 @@
 #!/usr/bin/pagsh.openafs
 
-# This script should go in /etc/init.d/ on Debian Linux systems running Domtool slaves.
+# This script should go in /etc/init.d/ on Debian Linux systems
+# running Domtool slaves.
 
 SELF=$(cd $(dirname $0); pwd -P)/$(basename $0)
-PIDFILE="/var/run/k5start-domtool-slave.pid"
+PIDFILE="/var/run/domtool/k5start-slave.pid"
 
 set -e
 
@@ -13,6 +14,12 @@ case $1 in
        if sudo -u domtool domtool-admin-sudo slave-ping; then
                echo "...already running."
        else
+               PIDDIR=$(dirname "$PIDFILE")
+               if test ! -d "$PIDDIR"; then
+                       mkdir -m 0755 $PIDDIR
+                       chown domtool:domtool $PIDDIR
+               fi
+
                start-stop-daemon --start --pidfile $PIDFILE \
                        -c domtool:domtool \
                        --exec /usr/bin/k5start -- -U -b \
@@ -35,7 +42,7 @@ case $1 in
        ;;
 
   restart|reload|force-reload)
-       $SELF stop
+       set +e; $SELF stop; set -e
        $SELF start
        ;;