]> git.donarmstrong.com Git - dsa-puppet.git/blobdiff - modules/stunnel4/files/etc-init.d-stunnel4
soler: decomission rt#5890
[dsa-puppet.git] / modules / stunnel4 / files / etc-init.d-stunnel4
index 8549c40bdb59c1f5443208f6eb7c3ad0a7ac6444..8921c4fef51e846521a8cd96dc56dc0f04235f18 100755 (executable)
@@ -1,4 +1,10 @@
 #! /bin/sh -e
+
+##
+## THIS FILE IS UNDER PUPPET CONTROL. DON'T EDIT IT HERE.
+## USE: git clone git+ssh://$USER@puppet.debian.org/srv/puppet.debian.org/git/dsa-puppet.git
+##
+
 ### BEGIN INIT INFO
 # Provides:          stunnel4
 # Required-Start:    $local_fs $remote_fs
@@ -14,10 +20,22 @@ DEFAULTPIDFILE="/var/run/stunnel4.pid"
 DAEMON=/usr/bin/stunnel4
 NAME=stunnel
 DESC="SSL tunnels"
-FILES="/etc/stunnel/*.conf"
 OPTIONS=""
 ENABLED=0
 
+ulimit -n 4096
+
+if [ -n "${2:-}" ]; then
+       if [ -e "/etc/stunnel/$2.conf" ]; then
+               FILES="/etc/stunnel/$2.conf"
+       else
+               echo >&2 "/etc/stunnel/$2.conf does not exist."
+               exit 1
+       fi
+else
+       FILES="/etc/stunnel/*.conf"
+fi
+
 get_pids() {
    local file=$1
    if test -f $file; then
@@ -58,10 +76,19 @@ killdaemons()
 {
   for file in $FILES; do
     PROCLIST=`get_pids $file`
-    if [ "$PROCLIST" ] && kill -0 $PROCLIST 2>/dev/null; then
-       kill $PROCLIST
-       echo -n "[stopped: $file] "
-    fi
+    for p in $PROCLIST; do
+      #start-stop-daemon --stop --retry 30 --pid "$p"
+      # start-stop-daemon in wheezy does not have a --pid yet, it interprets it as --pidfile
+      kill "$p"
+      c=150
+      while [ "$c" -gt 0 ] && kill -0 "$p" 2> /dev/null ; do
+        sleep 0.20
+        c=$((c - 1))
+        [ "$((c % 5))" = 0 ] && echo -n .
+      done
+      if kill -0 "$p" 2> /dev/null; then kill -9 "$p"; fi
+      echo -n "[stopped: $file] "
+    done
   done
 }
 
@@ -95,13 +122,13 @@ case "$1" in
   force-reload|restart)
         echo -n "Restarting $DESC: "
         killdaemons
-        sleep 5
+        #sleep 5
         startdaemons
         echo "$NAME."
         ;;
   *)
         N=/etc/init.d/$NAME
-        echo "Usage: $N {start|stop|force-reload|restart}" >&2
+        echo "Usage: $N {start|stop|force-reload|restart} [<stunnel instance>]" >&2
         exit 1
         ;;
 esac