Project

General

Profile

Download (8.52 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:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled -Duser.home=$CDM_HOME -Dcdm.logDir=$LOGDIR"
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-gcj \
69
    /usr/lib/kaffe/ \
70
   "
71

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

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

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

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

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

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

    
93
#### finally compile overridable variables
94
CDMSERVER_ARGS="-httpPort=$CDMSERVER_PORT -contextPathPrefix=$CONTEXT_PATH_PREFIX $CDMSERVER_ARGS"
95

    
96
#### setting java home for JSVC ####
97

    
98

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

    
106
### configuring environment to use jemalloc for the jvm (see https://dev.e-taxonomy.eu/redmine/issues/5048)
107
export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.1
108

    
109

    
110
#BOOTSTRAP_CLASS="eu.etaxonomy.cdm.server.Bootloader"
111
BOOTSTRAP_CLASS="eu.etaxonomy.cdm.server.jsvc.ServiceWrapper"
112

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

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

    
123

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

    
136
  if start-stop-daemon --quiet --test --start --pidfile "$PIDFILE" \
137
        --user "$CDM_USER" --startas "$JAVA" > /dev/null
138
  then
139

    
140
    if [ -f $PIDFILE ] ; then
141
      log_warning_msg "$PIDFILE exists, but cdmserver was not running. Ignoring $PIDFILE"
142
    fi
143

    
144
    echo $JSVC_CLASSPATH
145
    echo $JAVA_OPTIONS $BOOTSTRAP_CLASS  $CDMSERVER_ARGS
146

    
147
    # increasing the maximum number of open files
148
    ulimit -n 200000
149
    
150
    LOGFILE=$LOGDIR/startup.log
151
    
152
    rm -f $LOGFILE
153

    
154
    $DAEMON -home "$JAVA_HOME" -user "$CDM_USER" -jvm $JSVC_JVM -cp $JSVC_CLASSPATH \
155
        -outfile $LOGFILE -errfile $LOGFILE \
156
        -pidfile "$PIDFILE" $JAVA_OPTIONS $BOOTSTRAP_CLASS  $CDMSERVER_ARGS
157

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

    
168

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

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

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

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

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

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

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

    
251
case "$1" in
252

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

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

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

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

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

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

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

    
323
:
(3-3/7)