Whitespace fixing.
[fwd] / debian / fwd.init
1 #! /bin/sh
2 ### BEGIN INIT INFO
3 # Provides: fwd
4 # Required-Start: $local_fs $remote_fs
5 # Required-Stop: $local_fs $remote_fs
6 # Default-Start: 2 3 4 5
7 # Default-Stop: 0 1 6
8 # Short-Description: Start port forwarding server
9 # Description: This file should be used to construct scripts to be
10 # placed in /etc/init.d.
11 ### END INIT INFO
12
13 # Author: Mark Wooding <mdw@distorted.org.uk>
14
15 # Do NOT "set -e"
16
17 # PATH should only include /usr/* if it runs after the mountnfs.sh script
18 PATH=/sbin:/usr/sbin:/bin:/usr/bin
19 DESC="port forwarding daemon"
20 NAME=fwd
21 DAEMON=/usr/bin/fwd
22 PIDFILE=/var/run/$NAME.pid
23 SCRIPTNAME=/etc/init.d/$NAME
24 FWUSER=fwd FWGROUP=fwd
25 DAEMON_ARGS="--syslog"
26 CONFIG=/etc/fwd.conf
27 OLDCONFIG=/etc/fw.conf
28
29 # Exit if the package is not installed
30 [ -x "$DAEMON" ] || exit 0
31
32 # Read configuration variable file if it is present
33 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
34
35 # Exit if no configuration file
36 if [ -r "$CONFIG" ] && [ -r "$OLDCONFIG" ]; then
37 log_warning_message \
38 "Using old config file /etc/fw.conf. Please rename it to /etc/fwd.conf."
39 CONFIG=$OLDCONFIG
40 fi
41 [ -r "$CONFIG" ] || exit 0
42
43 # Load the VERBOSE setting and other rcS variables
44 . /lib/init/vars.sh
45
46 # Define LSB log_* functions.
47 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
48 . /lib/lsb/init-functions
49
50 #
51 # Function that starts the daemon/service
52 #
53 do_start()
54 {
55 # Return
56 # 0 if daemon has been started
57 # 1 if daemon was already running
58 # 2 if daemon could not be started
59 start-stop-daemon --start --quiet --pidfile $PIDFILE \
60 --exec $DAEMON --test > /dev/null \
61 || return 1
62 start-stop-daemon --start --quiet --pidfile $PIDFILE \
63 --exec $DAEMON -- \
64 --pidfile="$PIDFILE" \
65 --daemon \
66 $DAEMON_ARGS \
67 --setuid="$FWUSER" --setgid="$FWGROUP" \
68 --file="$CONFIG" \
69 || return 2
70 }
71
72 #
73 # Function that stops the daemon/service
74 #
75 do_stop()
76 {
77 # Return
78 # 0 if daemon has been stopped
79 # 1 if daemon was already stopped
80 # 2 if daemon could not be stopped
81 # other if a failure occurred
82 start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 \
83 --pidfile "$PIDFILE" --name $NAME
84 RETVAL="$?"
85 [ "$RETVAL" = 2 ] && return 2
86 rm -f "$PIDFILE"
87 return "$RETVAL"
88 }
89
90 #
91 # Function that sends a SIGHUP to the daemon/service
92 #
93 do_reload() {
94 #
95 # If the daemon can reload its configuration without
96 # restarting (for example, when it is sent a SIGHUP),
97 # then implement that here.
98 #
99 start-stop-daemon --stop --signal 1 --quiet --pidfile "$PIDFILE" \
100 --name $NAME
101 return 0
102 }
103
104 case "$1" in
105 start)
106 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
107 do_start
108 case "$?" in
109 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
110 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
111 esac
112 ;;
113 stop)
114 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
115 do_stop
116 case "$?" in
117 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
118 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
119 esac
120 ;;
121 reload|force-reload)
122 log_daemon_msg "Reloading $DESC" "$NAME"
123 do_reload
124 log_end_msg $?
125 ;;
126 restart)
127 log_daemon_msg "Restarting $DESC" "$NAME"
128 do_stop
129 case "$?" in
130 0|1)
131 do_start
132 case "$?" in
133 0) log_end_msg 0 ;;
134 1) log_end_msg 1 ;; # Old process is still running
135 *) log_end_msg 1 ;; # Failed to start
136 esac
137 ;;
138 *)
139 # Failed to stop
140 log_end_msg 1
141 ;;
142 esac
143 ;;
144 *)
145 echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
146 exit 3
147 ;;
148 esac
149
150 :