Project

General

Profile

Download (7.5 KB) Statistics
| Branch: | Tag: | Revision:
1
#! /bin/sh -e
2
#
3
# /etc/init.d/cdmserver -- startup script for cdmserver
4
#
5
# Author: Andreas Kohlbecker <a.kohlbecker@bgbm.org>
6
#
7
### BEGIN INIT INFO
8
# Provides:          CDM Server
9
# Required-Start:    $local_fs $remote_fs
10
# Required-Stop:     $local_fs $remote_fs
11
# Default-Start:     2 3 4 5
12
# Default-Stop:      0 1 6
13
# Short-Description: Start CDM Server daemon
14
# Description:       Starts CDM Server daemon which provides a webservice to access CDM Stores
15
### END INIT INFO
16

    
17
# Configuration files are found in
18
# /etc/cdmserver/.cdmLibrary
19

    
20
# install init script:		update-rc.d cdmserver defaults
21
# uninstall init script:	update-rc.d -f cdmserver remove
22

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

    
34

    
35
CDMSERVER_PORT=8080
36
JAVA_ARGS="-Xmx1024M -XX:PermSize=128m -XX:MaxPermSize=192m -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled -Duser.home=$CDM_HOME"
37
CDMSERVER_ARGS="-httpPort=$CDMSERVER_PORT -logdir=$LOGDIR"
38

    
39
# Define other required variables
40
PIDFILE=/var/run/$NAME.pid
41
SCRIPTNAME=/etc/init.d/$NAME
42

    
43
# Timeout in seconds for the shutdown of all webapps
44
CDMSERVER_SHUTDOWN=30
45

    
46
# Exit if the package is not installed
47
[ -x "$DAEMON" ] || exit 0
48

    
49
# Read configuration variable file if it is present
50
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
51

    
52
# Load the VERBOSE setting and other rcS variables
53
[ -f /etc/default/rcS ] && . /etc/default/rcS
54

    
55
# Define LSB log_* functions.
56
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
57
. /lib/lsb/init-functions
58

    
59

    
60
#### setting java home for JSVC ####
61

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

    
79
# Look for the right JVM to use
80
for jdir in $JDK_DIRS; do
81
	if [ -d "$jdir" -a -z "${JAVA_HOME}" ]; then
82
		JAVA_HOME="$jdir"
83
	fi
84
done
85
export JAVA_HOME
86

    
87
#BOOTSTRAP_CLASS="eu.etaxonomy.cdm.server.Bootloader"
88
BOOTSTRAP_CLASS="eu.etaxonomy.cdm.server.jsvc.ServiceWrapper"
89
JSVC_CLASSPATH="/usr/share/java/commons-daemon.jar:$JAVA_HOME/lib/tools.jar:$CDM_HOME/cdm-server.jar"
90
JSVC_JVM="server"
91

    
92
# Check for JAVA_HOME
93
if [ -z "$JAVA_HOME" ]; then
94
	log_failure_msg "Could not start $DESC because no Java Development Kit"
95
	log_failure_msg "(JDK) was found. Please download and install JDK 1.4 or higher and set"
96
	log_failure_msg "JAVA_HOME in /etc/default/jetty to the JDK's installation directory."
97
	exit 0
98
fi
99

    
100

    
101
#
102
# Function that starts the daemon/service
103
#
104
do_start()
105
{
106
  #[ -e "$LOG" ] && cnt=`wc -l "$LOG" | awk '{ print $1 }'` || cnt=1
107
	# Return
108
	#   0 if daemon has been started
109
	#   1 if daemon was already running
110
	#   2 if daemon could not be started
111
	log_daemon_msg "Starting $DESC." "$NAME : java $JAVA_OPTIONS -jar $CDM_HOME/cdm-server.jar $CDMSERVER_ARGS"
112

    
113
	if start-stop-daemon --quiet --test --start --pidfile "$PIDFILE" \
114
				--user "$CDM_USER" --startas "$JAVA" > /dev/null
115
	then
116

    
117
		if [ -f $PIDFILE ] ; then
118
			log_warning_msg "$PIDFILE exists, but cdmserver was not running. Ignoring $PIDFILE"
119
		fi
120

    
121
		chown -R $CDM_USER:adm "$LOGDIR"
122

    
123
		echo $JSVC_CLASSPATH
124
		echo $JAVA_OPTIONS $BOOTSTRAP_CLASS  $CDMSERVER_ARGS
125

    
126
		$DAEMON -user "$CDM_USER" -jvm $JSVC_JVM -cp $JSVC_CLASSPATH \
127
		    -outfile $LOGDIR/out.log -errfile $LOGDIR/out.log \
128
		    -pidfile "$PIDFILE" $JAVA_OPTIONS $BOOTSTRAP_CLASS  $CDMSERVER_ARGS
129

    
130

    
131
		sleep 5
132
		if start-stop-daemon --test --start --pidfile "$PIDFILE" \
133
			--user $CDM_USER --startas "$JAVA" >/dev/null; then
134
			log_daemon_msg "$DESC did not start, please check ${LOGDIR}/out.log" "$NAME"
135
			return 2
136
		else
137
			log_daemon_msg "$DESC started, reachable on http://localhost:$CDMSERVER_PORT/." "$NAME"
138
			return 0
139
		fi
140

    
141

    
142
	else
143
		log_warning_msg "(already running)."
144
		exit 1
145
	fi
146
}
147

    
148
#
149
# Function that stops the daemon/service
150
#
151
do_stop()
152
{
153
	# Return
154
	#   0 if daemon has been stopped
155
	#   1 if daemon was already stopped
156
	#   2 if daemon could not be stopped
157
	#   other if a failure occurred
158
	log_daemon_msg "Stopping $DESC." "$NAME"
159

    
160
	if start-stop-daemon --quiet --test --start --pidfile "$PIDFILE" \
161
				--user "$CDM_USER" --startas "$JAVA" > /dev/null
162
	then
163
		if [ -x "$PIDFILE" ]; then
164
			log_warning_msg "(not running but $PIDFILE exists)."
165
		else
166
			log_warning_msg "(not running)."
167
		fi
168
	else
169
		start-stop-daemon --quiet --stop \
170
			--pidfile $PIDFILE --user "$CDM_USER" --startas "$JAVA"  > /dev/null
171

    
172
		while ! start-stop-daemon --quiet --test --start \
173
			  --pidfile "$PIDFILE" --user "$CDM_USER" --startas "$JAVA" > /dev/null; do
174
			sleep 1
175
			log_progress_msg "."
176
			CDMSERVER_SHUTDOWN=`expr $CDMSERVER_SHUTDOWN - 1` || true
177
			if [ $CDMSERVER_SHUTDOWN -ge 0 ]; then
178
				start-stop-daemon --oknodo --quiet --stop \
179
					--pidfile "$PIDFILE" --user "$CDM_USER" \
180
					--startas "$JAVA"
181
			else
182
				log_progress_msg " (killing) "
183
				start-stop-daemon --stop --signal 9 --oknodo \
184
					--quiet --pidfile "$PIDFILE" \
185
					--user "$CDM_USER"
186
			fi
187
		done
188
		rm -f $PIDFILE
189
		log_daemon_msg "$DESC stopped." "$NAME"
190
	fi
191
	return "$RETVAL"
192
}
193

    
194
#
195
# Function that sends a SIGHUP to the daemon/service
196
#
197
do_reload() {
198
	#
199
	# If the daemon can reload its configuration without
200
	# restarting (for example, when it is sent a SIGHUP),
201
	# then implement that here.
202
	#
203
	start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
204
	return 0
205
}
206

    
207
report_status() {
208
	if start-stop-daemon --quiet --test --start --pidfile "$PIDFILE" \
209
		--user "$CDM_USER" --startas "$JAVA" > /dev/null; then
210

    
211
		if [ -f "$PIDFILE" ]; then
212
		    log_success_msg "$DESC is not running, but pid file exists."
213
			exit 1
214
		else
215
		    log_success_msg "$DESC is not running."
216
			exit 3
217
		fi
218
	else
219
		log_success_msg "$DESC is running with pid `cat $PIDFILE`, and is reachable on http://localhost:$CDMSERVER_PORT/"
220
	fi
221
}
222

    
223
case "$1" in
224

    
225
	start)
226
	do_start
227
	case "$?" in
228
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
229
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
230
	esac
231
	;;
232

    
233
	debug)
234
		JAVA_ARGS=" -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 $JAVA_ARGS"
235
		do_start
236
		case "$?" in
237
				0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
238
				2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
239
		esac
240
	;;
241

    
242
	stop)
243
	do_stop
244
	case "$?" in
245
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
246
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
247
	esac
248
	;;
249

    
250
	#reload|force-reload)
251
	#
252
	# If do_reload() is not implemented then leave this commented out
253
	# and leave 'force-reload' as an alias for 'restart'.
254
	#
255
	#log_daemon_msg "Reloading $DESC" "$NAME"
256
	#do_reload
257
	#log_end_msg $?
258
	#;;
259

    
260
	restart|force-reload)
261
	#
262
	# If the "reload" option is implemented then remove the
263
	# 'force-reload' alias
264
	#
265
	log_daemon_msg "Restarting $DESC" "$NAME"
266
	do_stop
267
	case "$?" in
268
		0|1)
269
		do_start
270
		case "$?" in
271
			0) log_end_msg 0 ;;
272
			1) log_end_msg 1 ;; # Old process is still running
273
			*) log_end_msg 1 ;; # Failed to start
274
		esac
275
		;;
276
		*)
277
		# Failed to stop
278
		log_end_msg 1
279
		;;
280
	esac
281
	;;
282

    
283
	status)
284
		report_status
285
		log_end_msg 0
286
	;;
287

    
288
	*)
289
	#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
290
	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status|debug}" >&2
291
	exit 3
292
	;;
293
esac
294

    
295
:
(3-3/6)