Project

General

Profile

Download (8.53 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:          cdmserver
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
# Should-Start:      mysql postgresql
19
# Short-Description: Start CDM Server daemon
20
# Description:       Starts CDM Server daemon which provides a webservice to access CDM Stores
21
### END INIT INFO
22

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

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

    
29

    
30
######################################################################
31
# variables that can be overwritten in /etc/default/cdmserver
32

    
33
NAME=cdmserver
34
DESC="CDM Server"
35
CDM_HOME=/opt/cdmserver
36
CDM_USER="cdm"
37
CDM_GROUP="cdm"
38
LOGDIR="/var/log/$NAME"
39
JAVA=/usr/bin/java
40
DAEMON=/usr/bin/jsvc
41

    
42
CONTEXT_PATH_PREFIX=/
43

    
44
CDMSERVER_PORT=8080
45

    
46
CDMSERVER_ARGS=""
47

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

    
50
JSVC_JVM="server"
51

    
52
# PATH should only include /usr/* if it runs after the mountnfs.sh script
53
PATH=/usr/sbin:/usr/bin:/sbin:/bin
54

    
55
# Define other required variables
56
PIDFILE=/var/run/$NAME.pid
57
SCRIPTNAME=/etc/init.d/$NAME
58

    
59
# Timeout in seconds for the shutdown of all webapps
60
CDMSERVER_SHUTDOWN=30
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
# End of variables that can be overwritten in /etc/default/cdmserver
80
######################################################################
81

    
82
if [ `id -u` -ne 0 ]; then
83
  echo "You need root privileges to run this script"
84
  exit 1
85
fi
86

    
87
# Exit if the package is not installed
88
[ -x "$DAEMON" ] || exit 0
89

    
90
# Read configuration variable file if it is present
91
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
92

    
93
# Load the VERBOSE setting and other rcS variables
94
[ -f /etc/default/rcS ] && . /etc/default/rcS
95

    
96
# Define LSB log_* functions.
97
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
98
. /lib/lsb/init-functions
99

    
100
#### finally compile overridable variables
101
CDMSERVER_ARGS="-httpPort=$CDMSERVER_PORT -logdir=$LOGDIR -contextPathPrefix=$CONTEXT_PATH_PREFIX $CDMSERVER_ARGS"
102

    
103
#### setting java home for JSVC ####
104

    
105

    
106
# Look for the right JVM to use
107
for jdir in $JDK_DIRS; do
108
  if [ -d "$jdir" -a -z "${JAVA_HOME}" ]; then
109
    JAVA_HOME="$jdir"
110
  fi
111
done
112

    
113
#BOOTSTRAP_CLASS="eu.etaxonomy.cdm.server.Bootloader"
114
BOOTSTRAP_CLASS="eu.etaxonomy.cdm.server.jsvc.ServiceWrapper"
115

    
116
JSVC_CLASSPATH="/usr/share/java/commons-daemon.jar:${JAVA_HOME}/lib/tools.jar:$CDM_HOME/cdm-server.jar"
117

    
118
# Check for JAVA_HOME
119
if [ -z "$JAVA_HOME" ]; then
120
  log_failure_msg "Could not start $DESC because no Java Development Kit"
121
  log_failure_msg "(JDK) was found. Please download and install JDK 1.6 or higher and set"
122
  log_failure_msg "JAVA_HOME in /etc/default/cdmserver to the JDK's installation directory."
123
  exit 0
124
fi
125

    
126

    
127
#
128
# Function that starts the daemon/service
129
#
130
do_start()
131
{
132
  #[ -e "$LOG" ] && cnt=`wc -l "$LOG" | awk '{ print $1 }'` || cnt=1
133
  # Return
134
  #   0 if daemon has been started
135
  #   1 if daemon was already running
136
  #   2 if daemon could not be started
137
  log_daemon_msg "Starting $DESC ( java $JAVA_OPTIONS -jar $CDM_HOME/cdm-server.jar $CDMSERVER_ARGS )"
138

    
139
  if start-stop-daemon --quiet --test --start --pidfile "$PIDFILE" \
140
        --user "$CDM_USER" --startas "$JAVA" > /dev/null
141
  then
142

    
143
    if [ -f $PIDFILE ] ; then
144
      log_warning_msg "$PIDFILE exists, but cdmserver was not running. Ignoring $PIDFILE"
145
    fi
146

    
147
    echo $JSVC_CLASSPATH
148
    echo $JAVA_OPTIONS $BOOTSTRAP_CLASS  $CDMSERVER_ARGS
149

    
150
    # increasing the maximum number of open files
151
    ulimit -n 200000
152

    
153
    $DAEMON -home "$JAVA_HOME" -user "$CDM_USER" -jvm $JSVC_JVM -cp $JSVC_CLASSPATH \
154
        -outfile $LOGDIR/out.log -errfile $LOGDIR/out.log \
155
        -pidfile "$PIDFILE" $JAVA_OPTIONS $BOOTSTRAP_CLASS  $CDMSERVER_ARGS
156

    
157
    sleep 5
158
    if start-stop-daemon --test --start --pidfile "$PIDFILE" \
159
      --user $CDM_USER --startas "$JAVA" >/dev/null; then
160
      log_daemon_msg "$DESC did not start, please check ${LOGDIR}/out.log"
161
      return 2
162
    else
163
      log_daemon_msg "$DESC started, reachable on http://localhost:$CDMSERVER_PORT/."
164
      return 0
165
    fi
166

    
167

    
168
  else
169
    log_warning_msg "(already running)."
170
    exit 1
171
  fi
172
}
173

    
174
#
175
# Function that stops the daemon/service
176
#
177
do_stop()
178
{
179
  # Return
180
  #   0 if daemon has been stopped
181
  #   1 if daemon was already stopped
182
  #   2 if daemon could not be stopped
183
  #   other if a failure occurred
184
  log_daemon_msg "Stopping $DESC"
185

    
186
  if start-stop-daemon --quiet --test --start --pidfile "$PIDFILE" \
187
        --user "$CDM_USER" --startas "$JAVA" > /dev/null
188
  then
189
    if [ -x "$PIDFILE" ]; then
190
      log_warning_msg "(not running but $PIDFILE exists)."
191
    else
192
      log_warning_msg "(not running)."
193
    fi
194
    return 1
195
  else
196
    start-stop-daemon --quiet --stop \
197
      --pidfile $PIDFILE --user "$CDM_USER" --startas "$JAVA"  > /dev/null
198

    
199
    while ! start-stop-daemon --quiet --test --start \
200
        --pidfile "$PIDFILE" --user "$CDM_USER" --startas "$JAVA" > /dev/null; do
201
      sleep 1
202
      log_progress_msg "."
203
      CDMSERVER_SHUTDOWN=`expr $CDMSERVER_SHUTDOWN - 1` || true
204
      if [ $CDMSERVER_SHUTDOWN -ge 0 ]; then
205
        start-stop-daemon --oknodo --quiet --stop \
206
          --pidfile "$PIDFILE" --user "$CDM_USER" \
207
          --startas "$JAVA"
208
      else
209
        log_progress_msg " (killing) "
210
        start-stop-daemon --stop --signal 9 --oknodo \
211
          --quiet --pidfile "$PIDFILE" \
212
          --user "$CDM_USER"
213
      fi
214
    done
215
    rm -f $PIDFILE
216
    log_daemon_msg "$DESC stopped."
217
  fi
218
  return 0
219
}
220

    
221
#
222
# Function that sends a SIGHUP to the daemon/service
223
#
224
do_reload() {
225
  #
226
  # If the daemon can reload its configuration without
227
  # restarting (for example, when it is sent a SIGHUP),
228
  # then implement that here.
229
  #
230
  start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
231
  return 0
232
}
233

    
234
report_status() {
235
  if start-stop-daemon --quiet --test --start --pidfile "$PIDFILE" \
236
    --user "$CDM_USER" --startas "$JAVA" > /dev/null; then
237

    
238
    if [ -f "$PIDFILE" ]; then
239
        log_success_msg "$DESC is not running, but pid file exists."
240
      exit 1
241
    else
242
        log_success_msg "$DESC is not running."
243
      exit 3
244
    fi
245
  else
246
    log_success_msg "$DESC is running with pid `cat $PIDFILE`, and is reachable on http://localhost:$CDMSERVER_PORT/"
247
  fi
248
}
249

    
250
case "$1" in
251

    
252
  start)
253
  do_start
254
  case "$?" in
255
    0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
256
    2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
257
  esac
258
  ;;
259

    
260
  debug)
261
    JAVA_OPTIONS=" -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 $JAVA_OPTIONS"
262
    do_start
263
    case "$?" in
264
        0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
265
        2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
266
    esac
267
  ;;
268

    
269
  stop)
270
  do_stop
271
  case "$?" in
272
    0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
273
    2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
274
  esac
275
  ;;
276

    
277
  #reload|force-reload)
278
  #
279
  # If do_reload() is not implemented then leave this commented out
280
  # and leave 'force-reload' as an alias for 'restart'.
281
  #
282
  #log_daemon_msg "Reloading $DESC" "$NAME"
283
  #do_reload
284
  #log_end_msg $?
285
  #;;
286

    
287
  restart|force-reload)
288
  #
289
  # If the "reload" option is implemented then remove the
290
  # 'force-reload' alias
291
  #
292
  log_daemon_msg "Restarting $DESC"
293
  do_stop
294
  case "$?" in
295
    0|1)
296
    do_start
297
    case "$?" in
298
      0) log_end_msg 0 ;;
299
      1) log_end_msg 1 ;; # Old process is still running
300
      *) log_end_msg 1 ;; # Failed to start
301
    esac
302
    ;;
303
    *)
304
    # Failed to stop
305
    log_end_msg 1
306
    ;;
307
  esac
308
  ;;
309

    
310
  status)
311
    report_status
312
    log_end_msg 0
313
  ;;
314

    
315
  *)
316
  #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
317
  echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status|debug}" >&2
318
  exit 3
319
  ;;
320
esac
321

    
322
:
(3-3/7)