]> git.donarmstrong.com Git - dsa-puppet.git/blob - modules/stunnel4/files/etc-init.d-stunnel4
Fix stomping of certfile
[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 ulimit -n 4096
27
28 if [ -n "${2:-}" ]; then
29         if [ -e "/etc/stunnel/$2.conf" ]; then
30                 FILES="/etc/stunnel/$2.conf"
31         else
32                 echo >&2 "/etc/stunnel/$2.conf does not exist."
33                 exit 1
34         fi
35 else
36         FILES="/etc/stunnel/*.conf"
37 fi
38
39 get_pids() {
40    local file=$1
41    if test -f $file; then
42      CHROOT=`grep "^chroot" $file|sed "s;.*= *;;"`
43      PIDFILE=`grep "^pid" $file|sed "s;.*= *;;"`
44      if [ "$PIDFILE" = "" ]; then
45        PIDFILE=$DEFAULTPIDFILE
46      fi
47      if test -f $CHROOT/$PIDFILE; then
48        cat $CHROOT/$PIDFILE
49      fi
50    fi
51 }
52
53 startdaemons() {
54   if ! [ -d /var/run/stunnel4 ]; then
55     rm -rf /var/run/stunnel4
56     install -d -o stunnel4 -g stunnel4 /var/run/stunnel4
57   fi
58   for file in $FILES; do 
59     if test -f $file; then
60       ARGS="$file $OPTIONS"
61       PROCLIST=`get_pids $file`
62       if [ "$PROCLIST" ] && kill -0 $PROCLIST 2>/dev/null; then
63         echo -n "[Already running: $file] "
64       elif $DAEMON $ARGS; then
65         echo -n "[Started: $file] "
66       else
67         echo "[Failed: $file]"
68         echo "You should check that you have specified the pid= in you configuration file"
69         exit 1
70       fi
71     fi
72   done;
73 }
74
75 killdaemons()
76 {
77   for file in $FILES; do
78     PROCLIST=`get_pids $file`
79     for p in $PROCLIST; do
80       #start-stop-daemon --stop --retry 30 --pid "$p"
81       # start-stop-daemon in wheezy does not have a --pid yet, it interprets it as --pidfile
82       kill "$p"
83       c=150
84       while [ "$c" -gt 0 ] && kill -0 "$p" 2> /dev/null ; do
85         sleep 0.20
86         c=$((c - 1))
87         [ "$((c % 5))" = 0 ] && echo -n .
88       done
89       if kill -0 "$p" 2> /dev/null; then kill -9 "$p"; fi
90       echo -n "[stopped: $file] "
91     done
92   done
93 }
94
95 if [ "x$OPTIONS" != "x" ]; then
96   OPTIONS="-- $OPTIONS"
97 fi
98
99 test -f /etc/default/stunnel4 && . /etc/default/stunnel4
100 if [ "$ENABLED" = "0" ] ; then
101   echo "$DESC disabled, see /etc/default/stunnel4"
102   exit 0
103 fi
104
105 test -x $DAEMON || exit 0
106
107 set -e
108
109 case "$1" in
110   start)
111         echo -n "Starting $DESC: "
112         startdaemons
113         echo "$NAME."
114         ;;
115   stop)
116         echo -n "Stopping $DESC: "
117         killdaemons
118         echo "$NAME."
119         ;;
120 #force-reload does not send a SIGHUP, since SIGHUP is interpreted as a 
121 #quit signal by stunnel. I reported this problem to upstream authors.
122   force-reload|restart)
123         echo -n "Restarting $DESC: "
124         killdaemons
125         #sleep 5
126         startdaemons
127         echo "$NAME."
128         ;;
129   *)
130         N=/etc/init.d/$NAME
131         echo "Usage: $N {start|stop|force-reload|restart} [<stunnel instance>]" >&2
132         exit 1
133         ;;
134 esac
135
136 exit 0