-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathsubstructure_search.initd
115 lines (103 loc) · 3.09 KB
/
substructure_search.initd
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
### BEGIN INIT INFO
# Provides: substructure_search
# Required-Start: $local_fs $network nginx
# Required-Stop: $local_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the substructure search service
# Description: starts the substructure search service using jsvc
### END INIT INFO
# substructure_search init.d script
#
# Copy or symlink this as /etc/init.d/substructure_search, and link it
# into all /etc/rc{0-6}.d directories as 'S99substructure_search'.
# This can be accomplished conveniently (as root) by running:
# $ update-rc.d substructure_search defaults 99
# and confirming that S99substructure_search exists in rc{2-5}.d.
#
# The configuration parameters in this script expect Java to have been
# installed using the `install_java` script, expectes `jsvc` to be
# available (installed using apt) and assumes the following files or
# directories exist:
#
# /usr/local/software/wiki_web_services/current.jar:
# Symlink to most recent version of the wiki services search JAR.
# /etc/wiki_web_services/substructure_config.json:
# Place the substructure search's configuration file here, and
# install any data files (like the reachables list) as necessary
# based on paths therein.
# /var/log/java/:
# Create a directory here for logs to be written to. TODO: use log
# rotation properly.
#
# This script supports common init.d verbs (start|stop|status|reload)
# and will report success or failure both on the consol and through
# its exit code ($?).
java_home="/usr/local/java/current"
user="www-data"
cwd="/tmp"
pid_file="/var/run/substructure.pid"
# Symlink the most recent version of the jar here:
jar="/usr/local/software/wiki_web_services/current.jar"
class="com.twentyn.search.substructure.Service"
args="-c /etc/wiki_web_services/substructure_config.json"
# TODO: replace these with log4j's rolling log appender
stdout="/var/log/java/substructure_search.out"
stderr="/var/log/java/substructure_search.err"
jsvc="/usr/bin/jsvc"
this_script=$0
jsvc_opts="-java-home $java_home -cwd $cwd -cp $jar -user $user -pidfile $pid_file -outfile $stdout -errfile $stderr"
is_running() {
if [[ -e $pid_file ]]; then
pid=$(cat $pid_file)
ps -p $pid >> /dev/null
result=$?
return $result
else
return 1
fi
}
start() {
if is_running; then
pid=$(cat $pid_file)
echo "Service is already running with pid $pid"
else
echo "Starting service with JSVC..."
$jsvc $jsvc_opts $class $args
pid=$(cat $pid_file)
echo "Service started with pid $pid"
fi
}
stop() {
if is_running; then
echo "Stopping service"
$jsvc $jsvc_opts -stop $class
else
echo "Service is not running"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
if is_running; then
echo "Running"
else
echo "Stopped"
exit 1
fi
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
;;
esac
exit 0