Project

General

Profile

Download (8.5 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/java-8-openjdk-amd64
66
    /usr/lib/jvm/default-java \
67
    /usr/lib/jvm/java-gcj \
68
    /usr/lib/kaffe/ \
69
   "
70

    
71
# End of variables that can be overwritten in /etc/default/cdmserver
72
######################################################################
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
#### finally compile overridable variables
93
CDMSERVER_ARGS="-httpPort=$CDMSERVER_PORT -contextPathPrefix=$CONTEXT_PATH_PREFIX $CDMSERVER_ARGS"
94

    
95
#### setting java home for JSVC ####
96

    
97

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

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

    
108

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

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

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

    
122

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

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

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

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

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

    
153
    $DAEMON -home "$JAVA_HOME" -user "$CDM_USER" -jvm $JSVC_JVM -cp $JSVC_CLASSPATH \
154
        -outfile $LOGFILE -errfile $LOGFILE \
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 $LOGFILE"
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
:
    (1-1/1)