Project

General

Profile

Download (7.78 KB) Statistics
| Branch: | Tag: | Revision:
1
#! /bin/sh -e
2
#
3
# /etc/init.d/cdmserver -- startup script for cdmserver
4
# Author: Andreas Kohlbecker <a.kohlbecker@bgbm.org>
5
#
6
# based on:
7
# 	/etc/init.d/jetty -- startup script for jetty 6.1.18
8
# 	Written by Philipp Meier <meier@meisterbohne.de>
9
# 	Modified for Jetty 6 by Ludovic Claude <ludovic.claude@laposte.net>
10
#
11
#
12
### BEGIN INIT INFO
13
# Provides:          CDM Server
14
# Required-Start:    $local_fs $remote_fs
15
# Required-Stop:     $local_fs $remote_fs
16
# Default-Start:     2 3 4 5
17
# Default-Stop:      0 1 6
18
# Short-Description: Start CDM Server daemon
19
# Description:       Starts CDM Server daemon which provides a webservice to access CDM Stores
20
### END INIT INFO
21

    
22
# Configuration files are found in
23
# /etc/cdmserver/.cdmLibrary
24

    
25
# install init script:		update-rc.d cdmserver defaults
26
# uninstall init script:	update-rc.d -f cdmserver remove
27

    
28
# PATH should only include /usr/* if it runs after the mountnfs.sh script
29
PATH=/usr/sbin:/usr/bin:/sbin:/bin
30
NAME=cdmserver
31
DESC="CDM Server"
32
CDM_HOME=/opt/cdmserver
33
CDM_USER="cdm"
34
CDM_GROUP="cdm"
35
LOGDIR="/var/log/$NAME"
36
JAVA=/usr/bin/java
37
DAEMON=/usr/bin/jsvc
38

    
39
CDMSERVER_PORT=8080
40

    
41
JAVA_OPTIONS="-Xmx1024M -XX:PermSize=128m -XX:MaxPermSize=192m -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled -Duser.home=$CDM_HOME"
42

    
43
CDMSERVER_ARGS="-httpPort=$CDMSERVER_PORT -logdir=$LOGDIR"
44

    
45
JSVC_CLASSPATH="/usr/share/java/commons-daemon.jar:${JAVA_HOME}lib/tools.jar:$CDM_HOME/cdm-server.jar"
46
JSVC_JVM="server"
47

    
48
# Define other required variables
49
PIDFILE=/var/run/$NAME.pid
50
SCRIPTNAME=/etc/init.d/$NAME
51

    
52
# Timeout in seconds for the shutdown of all webapps
53
CDMSERVER_SHUTDOWN=30
54

    
55
# The first existing directory is used for JAVA_HOME (if JAVA_HOME is not
56
# defined in /etc/default/jetty). Should contain a list of space separated directories.
57
JDK_DIRS="
58
	  /usr/lib/jvm/default-java \
59
	  /usr/lib/jvm/java-6-sun \
60
	  /usr/lib/jvm/java-6-openjdk \
61
	  /usr/lib/jvm/java-1.5.0-sun \
62
	  /usr/lib/jvm/java-gcj \
63
	  /usr/lib/j2sdk1.6-sun \
64
	  /usr/lib/j2sdk1.5-sun \
65
	  /usr/lib/j2sdk1.5-ibm \
66
	  /usr/lib/j2sdk1.4-sun \
67
	  /usr/lib/j2sdk1.4 \
68
	  /usr/lib/j2se/1.4 \
69
	  /usr/lib/kaffe/ \
70
	 "
71

    
72
# End of variables that can be overwritten in /etc/default/jetty
73

    
74
if [ `id -u` -ne 0 ]; then
75
	echo "You need root privileges to run this script"
76
	exit 1
77
fi
78

    
79
# Exit if the package is not installed
80
[ -x "$DAEMON" ] || exit 0
81

    
82
# Read configuration variable file if it is present
83
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
84

    
85
# Load the VERBOSE setting and other rcS variables
86
[ -f /etc/default/rcS ] && . /etc/default/rcS
87

    
88
# Define LSB log_* functions.
89
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
90
. /lib/lsb/init-functions
91

    
92

    
93
#### setting java home for JSVC ####
94

    
95

    
96
# Look for the right JVM to use
97
for jdir in $JDK_DIRS; do
98
	if [ -d "$jdir" -a -z "${JAVA_HOME}" ]; then
99
		JAVA_HOME="$jdir"
100
	fi
101
done
102

    
103
#BOOTSTRAP_CLASS="eu.etaxonomy.cdm.server.Bootloader"
104
BOOTSTRAP_CLASS="eu.etaxonomy.cdm.server.jsvc.ServiceWrapper"
105

    
106

    
107
# Check for JAVA_HOME
108
if [ -z "$JAVA_HOME" ]; then
109
	log_failure_msg "Could not start $DESC because no Java Development Kit"
110
	log_failure_msg "(JDK) was found. Please download and install JDK 1.4 or higher and set"
111
	log_failure_msg "JAVA_HOME in /etc/default/jetty to the JDK's installation directory."
112
	exit 0
113
fi
114

    
115

    
116
#
117
# Function that starts the daemon/service
118
#
119
do_start()
120
{
121
  #[ -e "$LOG" ] && cnt=`wc -l "$LOG" | awk '{ print $1 }'` || cnt=1
122
	# Return
123
	#   0 if daemon has been started
124
	#   1 if daemon was already running
125
	#   2 if daemon could not be started
126
	log_daemon_msg "Starting $DESC ( java $JAVA_OPTIONS -jar $CDM_HOME/cdm-server.jar $CDMSERVER_ARGS )"
127

    
128
	if start-stop-daemon --quiet --test --start --pidfile "$PIDFILE" \
129
				--user "$CDM_USER" --startas "$JAVA" > /dev/null
130
	then
131

    
132
		if [ -f $PIDFILE ] ; then
133
			log_warning_msg "$PIDFILE exists, but cdmserver was not running. Ignoring $PIDFILE"
134
		fi
135

    
136
		echo $JSVC_CLASSPATH
137
		echo $JAVA_OPTIONS $BOOTSTRAP_CLASS  $CDMSERVER_ARGS
138

    
139
		$DAEMON -home "$JAVA_HOME" -user "$CDM_USER" -jvm $JSVC_JVM -cp $JSVC_CLASSPATH \
140
		    -outfile $LOGDIR/out.log -errfile $LOGDIR/out.log \
141
		    -pidfile "$PIDFILE" $JAVA_OPTIONS $BOOTSTRAP_CLASS  $CDMSERVER_ARGS
142

    
143
		sleep 5
144
		if start-stop-daemon --test --start --pidfile "$PIDFILE" \
145
			--user $CDM_USER --startas "$JAVA" >/dev/null; then
146
			log_daemon_msg "$DESC did not start, please check ${LOGDIR}/out.log"
147
			return 2
148
		else
149
			log_daemon_msg "$DESC started, reachable on http://localhost:$CDMSERVER_PORT/."
150
			return 0
151
		fi
152

    
153

    
154
	else
155
		log_warning_msg "(already running)."
156
		exit 1
157
	fi
158
}
159

    
160
#
161
# Function that stops the daemon/service
162
#
163
do_stop()
164
{
165
	# Return
166
	#   0 if daemon has been stopped
167
	#   1 if daemon was already stopped
168
	#   2 if daemon could not be stopped
169
	#   other if a failure occurred
170
	log_daemon_msg "Stopping $DESC"
171

    
172
	if start-stop-daemon --quiet --test --start --pidfile "$PIDFILE" \
173
				--user "$CDM_USER" --startas "$JAVA" > /dev/null
174
	then
175
		if [ -x "$PIDFILE" ]; then
176
			log_warning_msg "(not running but $PIDFILE exists)."
177
		else
178
			log_warning_msg "(not running)."
179
		fi
180
		return 1
181
	else
182
		start-stop-daemon --quiet --stop \
183
			--pidfile $PIDFILE --user "$CDM_USER" --startas "$JAVA"  > /dev/null
184

    
185
		while ! start-stop-daemon --quiet --test --start \
186
			  --pidfile "$PIDFILE" --user "$CDM_USER" --startas "$JAVA" > /dev/null; do
187
			sleep 1
188
			log_progress_msg "."
189
			CDMSERVER_SHUTDOWN=`expr $CDMSERVER_SHUTDOWN - 1` || true
190
			if [ $CDMSERVER_SHUTDOWN -ge 0 ]; then
191
				start-stop-daemon --oknodo --quiet --stop \
192
					--pidfile "$PIDFILE" --user "$CDM_USER" \
193
					--startas "$JAVA"
194
			else
195
				log_progress_msg " (killing) "
196
				start-stop-daemon --stop --signal 9 --oknodo \
197
					--quiet --pidfile "$PIDFILE" \
198
					--user "$CDM_USER"
199
			fi
200
		done
201
		rm -f $PIDFILE
202
		log_daemon_msg "$DESC stopped."
203
	fi
204
	return 0
205
}
206

    
207
#
208
# Function that sends a SIGHUP to the daemon/service
209
#
210
do_reload() {
211
	#
212
	# If the daemon can reload its configuration without
213
	# restarting (for example, when it is sent a SIGHUP),
214
	# then implement that here.
215
	#
216
	start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
217
	return 0
218
}
219

    
220
report_status() {
221
	if start-stop-daemon --quiet --test --start --pidfile "$PIDFILE" \
222
		--user "$CDM_USER" --startas "$JAVA" > /dev/null; then
223

    
224
		if [ -f "$PIDFILE" ]; then
225
		    log_success_msg "$DESC is not running, but pid file exists."
226
			exit 1
227
		else
228
		    log_success_msg "$DESC is not running."
229
			exit 3
230
		fi
231
	else
232
		log_success_msg "$DESC is running with pid `cat $PIDFILE`, and is reachable on http://localhost:$CDMSERVER_PORT/"
233
	fi
234
}
235

    
236
case "$1" in
237

    
238
	start)
239
	do_start
240
	case "$?" in
241
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
242
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
243
	esac
244
	;;
245

    
246
	debug)
247
		JAVA_OPTIONS=" -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 $JAVA_OPTIONS"
248
		do_start
249
		case "$?" in
250
				0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
251
				2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
252
		esac
253
	;;
254

    
255
	stop)
256
	do_stop
257
	case "$?" in
258
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
259
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
260
	esac
261
	;;
262

    
263
	#reload|force-reload)
264
	#
265
	# If do_reload() is not implemented then leave this commented out
266
	# and leave 'force-reload' as an alias for 'restart'.
267
	#
268
	#log_daemon_msg "Reloading $DESC" "$NAME"
269
	#do_reload
270
	#log_end_msg $?
271
	#;;
272

    
273
	restart|force-reload)
274
	#
275
	# If the "reload" option is implemented then remove the
276
	# 'force-reload' alias
277
	#
278
	log_daemon_msg "Restarting $DESC"
279
	do_stop
280
	case "$?" in
281
		0|1)
282
		do_start
283
		case "$?" in
284
			0) log_end_msg 0 ;;
285
			1) log_end_msg 1 ;; # Old process is still running
286
			*) log_end_msg 1 ;; # Failed to start
287
		esac
288
		;;
289
		*)
290
		# Failed to stop
291
		log_end_msg 1
292
		;;
293
	esac
294
	;;
295

    
296
	status)
297
		report_status
298
		log_end_msg 0
299
	;;
300

    
301
	*)
302
	#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
303
	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status|debug}" >&2
304
	exit 3
305
	;;
306
esac
307

    
308
:
(3-3/6)