5ace7cb4a7d1a0ef65b16158f21dd5995255717c
[mirror/dsa-puppet.git] / modules / stunnel4 / files / etc-init.d-stunnel4
1 #! /bin/sh -e
2
3 ##
4 ## THIS FILE IS UNDER PUPPET CONTROL. DON'T EDIT IT HERE.
5 ## USE: git clone git+ssh://$USER@puppet.debian.org/srv/puppet.debian.org/git/dsa-puppet.git
6 ##
7
8 ### BEGIN INIT INFO
9 # Provides:          stunnel4
10 # Required-Start:    $local_fs $remote_fs
11 # Required-Stop:     $local_fs $remote_fs
12 # Should-Start:      $syslog
13 # Should-Stop:       $syslog
14 # Default-Start:     2 3 4 5
15 # Default-Stop:      0 1 6
16 # Short-Description: Start or stop stunnel 4.x (SSL tunnel for network daemons)
17 ### END INIT INFO
18
19 DEFAULTPIDFILE="/var/run/stunnel4.pid"
20 DAEMON=/usr/bin/stunnel4
21 NAME=stunnel
22 DESC="SSL tunnels"
23 OPTIONS=""
24 ENABLED=0
25
26 FILES="/etc/stunnel/*.conf"
27 if [ -n "${2-:}" ] && [ -e "/etc/stunnel/$2.conf" ]; then
28         FILES="/etc/stunnel/$2.conf}"
29 fi
30
31 get_pids() {
32    local file=$1
33    if test -f $file; then
34      CHROOT=`grep "^chroot" $file|sed "s;.*= *;;"`
35      PIDFILE=`grep "^pid" $file|sed "s;.*= *;;"`
36      if [ "$PIDFILE" = "" ]; then
37        PIDFILE=$DEFAULTPIDFILE
38      fi
39      if test -f $CHROOT/$PIDFILE; then
40        cat $CHROOT/$PIDFILE
41      fi
42    fi
43 }
44
45 startdaemons() {
46   if ! [ -d /var/run/stunnel4 ]; then
47     rm -rf /var/run/stunnel4
48     install -d -o stunnel4 -g stunnel4 /var/run/stunnel4
49   fi
50   for file in $FILES; do 
51     if test -f $file; then
52       ARGS="$file $OPTIONS"
53       PROCLIST=`get_pids $file`
54       if [ "$PROCLIST" ] && kill -0 $PROCLIST 2>/dev/null; then
55         echo -n "[Already running: $file] "
56       elif $DAEMON $ARGS; then
57         echo -n "[Started: $file] "
58       else
59         echo "[Failed: $file]"
60         echo "You should check that you have specified the pid= in you configuration file"
61         exit 1
62       fi
63     fi
64   done;
65 }
66
67 killdaemons()
68 {
69   for file in $FILES; do
70     PROCLIST=`get_pids $file`
71     if [ "$PROCLIST" ] && kill -0 $PROCLIST 2>/dev/null; then
72        kill $PROCLIST
73        echo -n "[stopped: $file] "
74     fi
75   done
76 }
77
78 if [ "x$OPTIONS" != "x" ]; then
79   OPTIONS="-- $OPTIONS"
80 fi
81
82 test -f /etc/default/stunnel4 && . /etc/default/stunnel4
83 if [ "$ENABLED" = "0" ] ; then
84   echo "$DESC disabled, see /etc/default/stunnel4"
85   exit 0
86 fi
87
88 test -x $DAEMON || exit 0
89
90 set -e
91
92 case "$1" in
93   start)
94         echo -n "Starting $DESC: "
95         startdaemons
96         echo "$NAME."
97         ;;
98   stop)
99         echo -n "Stopping $DESC: "
100         killdaemons
101         echo "$NAME."
102         ;;
103 #force-reload does not send a SIGHUP, since SIGHUP is interpreted as a 
104 #quit signal by stunnel. I reported this problem to upstream authors.
105   force-reload|restart)
106         echo -n "Restarting $DESC: "
107         killdaemons
108         sleep 5
109         startdaemons
110         echo "$NAME."
111         ;;
112   *)
113         N=/etc/init.d/$NAME
114         echo "Usage: $N {start|stop|force-reload|restart}" >&2
115         exit 1
116         ;;
117 esac
118
119 exit 0