Use start-stop-daemon for stopping/restarting stunnel4
[mirror/dsa-puppet.git] / modules / stunnel4 / files / etc-init.d-stunnel4
index 5ace7cb..7bc871a 100755 (executable)
@@ -23,9 +23,17 @@ DESC="SSL tunnels"
 OPTIONS=""
 ENABLED=0
 
-FILES="/etc/stunnel/*.conf"
-if [ -n "${2-:}" ] && [ -e "/etc/stunnel/$2.conf" ]; then
-       FILES="/etc/stunnel/$2.conf}"
+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() {
@@ -68,9 +76,9 @@ 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] "
+    for p in $PROCLIST; do
+      start-stop-daemon --stop --retry 30 --pid "$p"
+      echo -n "[stopped: $file] "
     fi
   done
 }
@@ -111,7 +119,7 @@ case "$1" in
         ;;
   *)
         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