-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtunneller.init.d.sh
executable file
·78 lines (67 loc) · 2.53 KB
/
tunneller.init.d.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#! /bin/bash
# This is the script to be called by init.d. Install it as per
# usual init.d script install procedures.
# Setup/Installation:
# Put JSVC in /usr/bin (or update its location below)
# Put tunneller.jar and all of the required libs in /usr/share/java
# Put required config files and stuff in /etc/tunneller
# This is a bit of a funny init.d script which calls
# itself with nohup. The reason it is done in this
# roundabout way is that restarting tunneller could restart
# the ssh tunnel that the admin is logged in through.
# The restart would kill the tunnel, which would hangup the
# admin's session, and thus hup any processes he's started -
# including this script. The result is that, when restarting,
# the script would die/stop executing before it got a chance
# to restart the tunnel. The nohup fixes this by ensuring
# this script will keep running even if our tty hangs up.
PROCESS_NAME=tunneller
START_CLASS=ca.brood.tunneller.Tunneller
HOME_DIR=/etc/tunneller
PID_FILE=/var/run/tunneller.pid
CPHOME=/usr/share/java
JSVC=/usr/bin/jsvc
JVM=/usr/lib/jvm/default-java
CP=$CPHOME/activation.jar:\
$CPHOME/brootils-1.0.jar:\
$CPHOME/commons-daemon-1.0.13.jar:\
$CPHOME/jsch-0.1.49.jar:\
$CPHOME/log4j-1.2.16.jar:\
$CPHOME/log4j-api-2.0-beta7.jar:\
$CPHOME/log4j-core-2.0-beta7.jar:\
$CPHOME/mail.jar:\
$CPHOME/tunneller-1.1.jar
# Verify the arguments before we nohup so we can send
# error messages to the tty instead of to nohup.out
if [ "$1" != "nohup" ] && [ "$1" != "start" ] && [ "$1" != "stop" ] && [ "$1" != "restart" ]; then
echo "Usage: $0 {start|stop|restart}"
exit 1
fi
# If the first argument is not nohup, then nohup this
# script.
if [ "$1" != "nohup" ]; then
nohup $0 nohup $1 &
exit 0
fi
# We only get here if this script has been called with nohup
case "$2" in
start)
echo -n "Starting daemon "
$JSVC -cp $CP -home $JVM -cwd $HOME_DIR -pidfile $PID_FILE -procname $PROCESS_NAME $START_CLASS
;;
stop)
echo -n "Shutting down daemon "
$JSVC -stop -cp $CP -home $JVM -cwd $HOME_DIR -pidfile $PID_FILE -procname $PROCESS_NAME $START_CLASS
;;
restart)
## Stop the service and regardless of whether it was
## running or not, then start it again.
$0 nohup stop
$0 nohup start
;;
*)
## If no parameters are given, print which are avaiable.
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac