1
|
#! /bin/sh
|
2
|
### BEGIN INIT INFO
|
3
|
# Provides: CDM Server
|
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: Starts CDMServer daemon
|
9
|
# Description: Starts CDMServer daemon which provides a RESTful webservice to access CDM Stores
|
10
|
### END INIT INFO
|
11
|
|
12
|
# install init script: update-rc.d cdmserver defaults
|
13
|
# uninstall init script: update-rc.d -f cdmserver remove
|
14
|
|
15
|
# Author: Andreas Kohlbecker
|
16
|
|
17
|
# Do NOT "set -e"
|
18
|
|
19
|
# PATH should only include /usr/* if it runs after the mountnfs.sh script
|
20
|
PATH=/usr/sbin:/usr/bin:/sbin:/bin
|
21
|
#CDM_HOME=/home/cdm
|
22
|
CDM_HOME=/opt/cdmserver
|
23
|
CDM_LIBRARY=$CDM_HOME".cdmLibrary"
|
24
|
DESC="CDM Server"
|
25
|
NAME=cdmserver
|
26
|
LOG="$CDM_HOME/$NAME.log"
|
27
|
DAEMON=/usr/bin/java
|
28
|
DAEMON_ARGS="-Xmx1024M -XX:PermSize=128m -XX:MaxPermSize=192m -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled -Duser.home=$CDM_HOME -jar "$CDM_HOME/cdm-server.jar""
|
29
|
PIDFILE=/var/run/$NAME.pid
|
30
|
SCRIPTNAME=/etc/init.d/$NAME
|
31
|
|
32
|
# Exit if the package is not installed
|
33
|
[ -x "$DAEMON" ] || exit 0
|
34
|
|
35
|
# Read configuration variable file if it is present
|
36
|
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
|
37
|
|
38
|
# Load the VERBOSE setting and other rcS variables
|
39
|
[ -f /etc/default/rcS ] && . /etc/default/rcS
|
40
|
|
41
|
# Define LSB log_* functions.
|
42
|
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
|
43
|
. /lib/lsb/init-functions
|
44
|
|
45
|
|
46
|
pid_of_cdmserver() {
|
47
|
cat "$PIDFILE"
|
48
|
}
|
49
|
|
50
|
#
|
51
|
# Function that starts the daemon/service
|
52
|
#
|
53
|
do_start()
|
54
|
{
|
55
|
#[ -e "$LOG" ] && cnt=`wc -l "$LOG" | awk '{ print $1 }'` || cnt=1
|
56
|
# Return
|
57
|
# 0 if daemon has been started
|
58
|
# 1 if daemon was already running
|
59
|
# 2 if daemon could not be started
|
60
|
# log_daemon_msg "Starting $DESC" "$NAME with $DAEMON_ARGS"
|
61
|
echo -ne "Starting $DESC" "$NAME with $DAEMON_ARGS"
|
62
|
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|
63
|
|| return 1
|
64
|
start-stop-daemon --start --pidfile $PIDFILE --make-pidfile --background --exec $DAEMON -- \
|
65
|
$DAEMON_ARGS \
|
66
|
|| return 2
|
67
|
# Add code here, if necessary, that waits for the process to be ready
|
68
|
# to handle requests from services started subsequently which depend
|
69
|
# on this one. As a last resort, sleep for some time.
|
70
|
#while { pid_of_cdmserver > /dev/null ; } &&
|
71
|
# ! { tail +$cnt "$LOG" | grep -q 'Winstone Servlet Engine .* running' ; } ; do
|
72
|
# sleep 1
|
73
|
#done
|
74
|
|
75
|
}
|
76
|
|
77
|
#
|
78
|
# Function that stops the daemon/service
|
79
|
#
|
80
|
do_stop()
|
81
|
{
|
82
|
# Return
|
83
|
# 0 if daemon has been stopped
|
84
|
# 1 if daemon was already stopped
|
85
|
# 2 if daemon could not be stopped
|
86
|
# other if a failure occurred
|
87
|
log_daemon_msg "Stopping $DESC" "$NAME"
|
88
|
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
|
89
|
RETVAL="$?"
|
90
|
[ "$RETVAL" = 2 ] && return 2
|
91
|
# Wait for children to finish too if this is a daemon that forks
|
92
|
# and if the daemon is only ever run from this initscript.
|
93
|
# If the above conditions are not satisfied then add some other code
|
94
|
# that waits for the process to drop all resources that could be
|
95
|
# needed by services started subsequently. A last resort is to
|
96
|
# sleep for some time.
|
97
|
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
|
98
|
[ "$?" = 2 ] && return 2
|
99
|
# Many daemons don't delete their pidfiles when they exit.
|
100
|
rm -f $PIDFILE
|
101
|
return "$RETVAL"
|
102
|
}
|
103
|
|
104
|
#
|
105
|
# Function that sends a SIGHUP to the daemon/service
|
106
|
#
|
107
|
do_reload() {
|
108
|
#
|
109
|
# If the daemon can reload its configuration without
|
110
|
# restarting (for example, when it is sent a SIGHUP),
|
111
|
# then implement that here.
|
112
|
#
|
113
|
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
|
114
|
return 0
|
115
|
}
|
116
|
|
117
|
case "$1" in
|
118
|
start)
|
119
|
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
|
120
|
do_start
|
121
|
case "$?" in
|
122
|
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
123
|
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
124
|
esac
|
125
|
;;
|
126
|
debug)
|
127
|
DAEMON_ARGS=" -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 $DAEMON_ARGS"
|
128
|
[ "$VERBOSE" != no ] && log_daemon_msg "Starting in debug mode $DESC" "$NAME"
|
129
|
do_start
|
130
|
case "$?" in
|
131
|
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
132
|
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
133
|
esac
|
134
|
;;
|
135
|
stop)
|
136
|
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
|
137
|
do_stop
|
138
|
case "$?" in
|
139
|
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
140
|
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
141
|
esac
|
142
|
;;
|
143
|
#reload|force-reload)
|
144
|
#
|
145
|
# If do_reload() is not implemented then leave this commented out
|
146
|
# and leave 'force-reload' as an alias for 'restart'.
|
147
|
#
|
148
|
#log_daemon_msg "Reloading $DESC" "$NAME"
|
149
|
#do_reload
|
150
|
#log_end_msg $?
|
151
|
#;;
|
152
|
restart|force-reload)
|
153
|
#
|
154
|
# If the "reload" option is implemented then remove the
|
155
|
# 'force-reload' alias
|
156
|
#
|
157
|
log_daemon_msg "Restarting $DESC" "$NAME"
|
158
|
do_stop
|
159
|
case "$?" in
|
160
|
0|1)
|
161
|
do_start
|
162
|
case "$?" in
|
163
|
0) log_end_msg 0 ;;
|
164
|
1) log_end_msg 1 ;; # Old process is still running
|
165
|
*) log_end_msg 1 ;; # Failed to start
|
166
|
esac
|
167
|
;;
|
168
|
*)
|
169
|
# Failed to stop
|
170
|
log_end_msg 1
|
171
|
;;
|
172
|
esac
|
173
|
;;
|
174
|
*)
|
175
|
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
|
176
|
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|debug}" >&2
|
177
|
exit 3
|
178
|
;;
|
179
|
esac
|
180
|
|
181
|
:
|