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