]> git.donarmstrong.com Git - dsa-puppet.git/commitdiff
Ship our own etc/init.d/stunnel4
authorPeter Palfrader <peter@palfrader.org>
Tue, 24 May 2011 09:51:23 +0000 (11:51 +0200)
committerPeter Palfrader <peter@palfrader.org>
Tue, 24 May 2011 09:51:43 +0000 (11:51 +0200)
modules/stunnel4/files/etc-init.d-stunnel4 [new file with mode: 0755]
modules/stunnel4/manifests/init.pp

diff --git a/modules/stunnel4/files/etc-init.d-stunnel4 b/modules/stunnel4/files/etc-init.d-stunnel4
new file mode 100755 (executable)
index 0000000..8549c40
--- /dev/null
@@ -0,0 +1,109 @@
+#! /bin/sh -e
+### BEGIN INIT INFO
+# Provides:          stunnel4
+# Required-Start:    $local_fs $remote_fs
+# Required-Stop:     $local_fs $remote_fs
+# Should-Start:      $syslog
+# Should-Stop:       $syslog
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Start or stop stunnel 4.x (SSL tunnel for network daemons)
+### END INIT INFO
+
+DEFAULTPIDFILE="/var/run/stunnel4.pid"
+DAEMON=/usr/bin/stunnel4
+NAME=stunnel
+DESC="SSL tunnels"
+FILES="/etc/stunnel/*.conf"
+OPTIONS=""
+ENABLED=0
+
+get_pids() {
+   local file=$1
+   if test -f $file; then
+     CHROOT=`grep "^chroot" $file|sed "s;.*= *;;"`
+     PIDFILE=`grep "^pid" $file|sed "s;.*= *;;"`
+     if [ "$PIDFILE" = "" ]; then
+       PIDFILE=$DEFAULTPIDFILE
+     fi
+     if test -f $CHROOT/$PIDFILE; then
+       cat $CHROOT/$PIDFILE
+     fi
+   fi
+}
+
+startdaemons() {
+  if ! [ -d /var/run/stunnel4 ]; then
+    rm -rf /var/run/stunnel4
+    install -d -o stunnel4 -g stunnel4 /var/run/stunnel4
+  fi
+  for file in $FILES; do 
+    if test -f $file; then
+      ARGS="$file $OPTIONS"
+      PROCLIST=`get_pids $file`
+      if [ "$PROCLIST" ] && kill -0 $PROCLIST 2>/dev/null; then
+        echo -n "[Already running: $file] "
+      elif $DAEMON $ARGS; then
+       echo -n "[Started: $file] "
+      else
+       echo "[Failed: $file]"
+       echo "You should check that you have specified the pid= in you configuration file"
+       exit 1
+      fi
+    fi
+  done;
+}
+
+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
+  done
+}
+
+if [ "x$OPTIONS" != "x" ]; then
+  OPTIONS="-- $OPTIONS"
+fi
+
+test -f /etc/default/stunnel4 && . /etc/default/stunnel4
+if [ "$ENABLED" = "0" ] ; then
+  echo "$DESC disabled, see /etc/default/stunnel4"
+  exit 0
+fi
+
+test -x $DAEMON || exit 0
+
+set -e
+
+case "$1" in
+  start)
+        echo -n "Starting $DESC: "
+        startdaemons
+        echo "$NAME."
+        ;;
+  stop)
+        echo -n "Stopping $DESC: "
+        killdaemons
+        echo "$NAME."
+        ;;
+#force-reload does not send a SIGHUP, since SIGHUP is interpreted as a 
+#quit signal by stunnel. I reported this problem to upstream authors.
+  force-reload|restart)
+        echo -n "Restarting $DESC: "
+        killdaemons
+        sleep 5
+        startdaemons
+        echo "$NAME."
+        ;;
+  *)
+        N=/etc/init.d/$NAME
+        echo "Usage: $N {start|stop|force-reload|restart}" >&2
+        exit 1
+        ;;
+esac
+
+exit 0
index 5e2b8a307f2272a9487c29029904f4e5e943bd74..b9335eaabd337fdf2b101544cad152cf68c4ade6 100644 (file)
@@ -11,6 +11,9 @@ class stunnel4 {
                 content => template("stunnel4/stunnel.conf.erb"),
                 notify  => Exec['restart_stunnel'],
                 ;
+            "/etc/init.d/stunnel4":
+                source => "puppet:///modules/stunnel4/etc-init.d-stunnel4",
+            ;
         }
     }