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