4 ### suitable for direct use in most SysV-style inits
8 # Required-Start: $local_fs $remote_fs $named $network
9 # Required-Stop: $local_fs $remote_fs $network
10 # Default-Start: 2 3 4 5
12 # Short-Description: tripe Virtual Private Network server
17 ###--------------------------------------------------------------------------
20 [ -f @initconfig@
] && . @initconfig@
22 : ${prefix=@prefix@} ${exec_prefix=@exec_prefix@}
23 : ${bindir=@bindir@} ${sbindir=@sbindir@}
24 : ${TRIPEDIR=@configdir@} ${TRIPESOCK=@socketdir@/tripesock}
25 : ${pidfile=@pidfile@}
26 : ${tripe=$sbindir/tripe} ${tripectl=$bindir/tripectl}
28 PATH
=/usr
/bin
:/usr
/sbin
:/bin
:/sbin
:$bindir
29 export PATH TRIPEDIR TRIPESOCK TRIPE_SLIPIF
31 ###--------------------------------------------------------------------------
32 ### Pre-flight checks.
34 ## Give up if there's no binary.
35 if test ! -x
"$tripe" ||
test ! -x
"$tripectl"; then
36 echo >&2 "Not starting/stopping TrIPE: binary files missing"
40 ## Give up if there's no key.
41 if test ! -f
"$TRIPEDIR/keyring" ||
test ! -f
"$TRIPEDIR/keyring.pub"; then
42 echo >&2 "Not starting/stopping TrIPE: keyring files missing"
46 ## Check it will work, or at least stands a fighting chance.
48 ## (Having loads of different tunnel types doesn't help any.)
49 case ${tunnel-`$tripe --tunnels | head -1`},`uname -s` in
53 if { test -f
/proc
/misc
&& grep -q tun
/proc
/misc
; } ||
57 echo >&2 "$tripe needs the Linux TUN/TAP driver to run."
60 if test -c
/dev
/net
/tun
; then
63 echo >&2 "$tripe needs /dev/net/tun, which is missing."
68 ## Linux Unet (obsolete).
70 if { test -f
/proc
/devices
&& grep -q unet
/proc
/devices
; } ||
71 modprobe
-q unet
; then
74 echo >&2 "$tripe needs the Linux UNET driver to run."
77 if test -c
/dev
/unet
; then
80 echo >&2 "$tripe needs /dev/unet, which is missing."
87 ## Don't know how to check the device is working. Check the device file
88 ## exists and hope for the best.
89 if test -c
/dev
/tun0
; then
92 echo >&2 "$tripe needs /dev/tun0, which is missing."
99 if test "$TRIPE_SLIPIF" = ""; then
100 echo >&2 "$tripe needs SLIP interfaces set up!"
105 ## Various kinds of misconfiguration.
107 echo >&2 "CONFIGURATION ERROR"
108 echo >&2 " $tripe is compiled to use a Linux tunnel device, but"
109 echo >&2 " this system is `uname -s`"
113 echo >&2 "CONFIGURATION ERROR"
114 echo >&2 " $tripe is compiled to use a BSD tunnel device, but"
115 echo >&2 " this system is `uname -s`"
120 ###--------------------------------------------------------------------------
121 ### Do what was wanted.
126 echo -n
"Starting TrIPE VPN daemon:"
128 ## Check to see whether the daemon is already going. If it can respond
129 ## to a simple request, we'll assume that it is.
130 if $tripectl version
>/dev
/null
2>/dev
/null
; then
131 echo " already running"
135 ## Start the server, passing lots of arguments.
136 $tripectl -D
-s
-p
$tripe \
138 -f
${logfile-@logfile@} \
139 ${keytag+-S-t$keytag} \
140 ${addr+-S-b$addr} ${port+-S-p$port} \
141 ${user+-U$user} ${group+-G$group} \
142 ${sockmode+-S-m$sockmode} \
143 ${trace+-S-T$trace} \
144 ${tunnel+-S-n$tunnel} \
147 ## Wait for the server to start up. This doesn't usually take long.
148 for i
in 1 2 3 4 give-up
; do
149 $tripectl help >/dev
/null
2>/dev
/null
&& break
153 if [ $i = give-up
]; then
154 echo " wouldn't start"
160 ## Start up the ancillary services.
161 sep
=" services [" end
=""
162 [ -d
$TRIPEDIR/services
] && for i
in $TRIPEDIR/services
/*; do
163 [ -x
$i ] ||
continue
165 case $name in *~|\
#*) continue;; esac
166 if $i --daemon
--startup
; then
169 echo -n
"$sep($name failed)"
175 ## Start up the statically configured peers.
176 sep
=" peers [" end
=""
177 [ -d
$TRIPEDIR/peers
] && for i
in $TRIPEDIR/peers
/*; do
178 [ -x
$i ] ||
continue
180 case $name in *~|\
#*) continue;; esac
184 echo -n
"$sep($name failed)"
194 echo -n
"Stopping TrIPE VPN daemon:"
196 ## If there's no socket, it must have quit (probably nonviolently).
197 if (cd $TRIPEDIR && test ! -S
$TRIPESOCK); then
200 ## Ask it to die nicely.
201 elif $tripectl quit
>/dev
/null
2>&1; then
204 ## If there's no pidfile then tripectl presumably deleted it.
205 elif test ! -f
$pidfile; then
206 echo " stale socket found: removing"
209 ## Otherwise kill the process unpleasantly.
210 elif kill `cat $pidfile`; then
211 echo " done (killed violently)"
213 echo " it doesn't want to die!"
219 for i
in `$tripectl list`; do
221 $tripectl stats
$i |
sed 's/^/ /'
227 echo "Keyrings reloaded OK."
230 restart | force-reload
)
236 echo >&2 "usage: $0 start|stop|restart|status|reload|force-reload"
242 ###----- That's all, folks --------------------------------------------------