Project

General

Profile

Download (8.35 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

    
29
######################################################################
30
# Start of variables that can be overwritten in /etc/default/cdmserver
31

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

    
41
CDMSERVER_PORT=8080
42

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

    
45
CDMSERVER_ARGS="-httpPort=$CDMSERVER_PORT -logdir=$LOGDIR"
46

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

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

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

    
57
# Timeout in seconds for the shutdown of all webapps
58
CDMSERVER_SHUTDOWN=30
59

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

    
77
# End of variables that can be overwritten in /etc/default/cdmserver
78
######################################################################
79

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

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

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

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

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

    
98

    
99
#### setting java home for JSVC ####
100

    
101

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

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

    
112

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

    
121

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

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

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

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

    
145
    # increasing the maximum number of open files
146
    ulimit -n 5000
147

    
148
    $DAEMON -home "$JAVA_HOME" -user "$CDM_USER" -jvm $JSVC_JVM -cp $JSVC_CLASSPATH \
149
        -outfile $LOGDIR/out.log -errfile $LOGDIR/out.log \
150
        -pidfile "$PIDFILE" $JAVA_OPTIONS $BOOTSTRAP_CLASS  $CDMSERVER_ARGS
151

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

    
162

    
163
  else
164
    log_warning_msg "(already running)."
165
    exit 1
166
  fi
167
}
168

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

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

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

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

    
229
report_status() {
230
  if start-stop-daemon --quiet --test --start --pidfile "$PIDFILE" \
231
    --user "$CDM_USER" --startas "$JAVA" > /dev/null; then
232

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

    
245
case "$1" in
246

    
247
  start)
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
  debug)
256
    JAVA_OPTIONS=" -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 $JAVA_OPTIONS"
257
    do_start
258
    case "$?" in
259
        0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
260
        2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
261
    esac
262
  ;;
263

    
264
  stop)
265
  do_stop
266
  case "$?" in
267
    0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
268
    2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
269
  esac
270
  ;;
271

    
272
  #reload|force-reload)
273
  #
274
  # If do_reload() is not implemented then leave this commented out
275
  # and leave 'force-reload' as an alias for 'restart'.
276
  #
277
  #log_daemon_msg "Reloading $DESC" "$NAME"
278
  #do_reload
279
  #log_end_msg $?
280
  #;;
281

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

    
305
  status)
306
    report_status
307
    log_end_msg 0
308
  ;;
309

    
310
  *)
311
  #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
312
  echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status|debug}" >&2
313
  exit 3
314
  ;;
315
esac
316

    
317
:
(3-3/7)