Mercurial > dive4elements > river
diff contrib/init.d/d4e-river @ 7738:1709c429818a
(issue1692) Ãberarbeitetes Init script
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Tue, 04 Feb 2014 11:08:57 +0100 |
parents | bc4e1bf26227 |
children | 0000ed802cad |
line wrap: on
line diff
--- a/contrib/init.d/d4e-river Fri Jan 31 19:57:35 2014 +0100 +++ b/contrib/init.d/d4e-river Tue Feb 04 11:08:57 2014 +0100 @@ -13,52 +13,141 @@ ### END INIT INFO RUNAS=flys -DIR="/opt/flys/current/server" +START_SCRIPT="/opt/flys/d4e-start" +NAME="$(basename $0)" +SHUTDOWN_WAIT="30" -CLASSPATH= -for l in `find "$DIR/bin/lib" -name \*.jar -print`; do - CLASSPATH=$CLASSPATH:$l -done +export FLYSDIR="/opt/flys/current/server" + +unset ISBOOT +if [ "${NAME:0:1}" = "S" -o "${NAME:0:1}" = "K" ]; then + NAME="${NAME:3}" + ISBOOT="1" +fi + +# remove SUSE's rc name +if [ "${NAME:0:2}" = "rc" ]; then + NAME="${NAME:2}" +fi -LOGFILE=/var/log/d4e-river.log -PIDFILE=/var/run/d4e-river.pid -ARGS="-Xmx256m \ +export LOGFILE=/var/log/d4e-river.log +export ARGS="-Xmx256m \ -server \ -Djava.awt.headless=true \ -Dflys.datacage.recommendations.development=false \ - -Djava.io.tmpdir=\"$DIR/cache\" \ + -Djava.io.tmpdir=$FLYSDIR/cache \ + -Dflys.backend.enablejmx=true \ -Dflys.uesk.keep.artifactsdir=false \ - -Dwsplgen.bin.path=\"$DIR/bin/wsplgen.exe\" \ + -Dwsplgen.bin.path=$FLYSDIR/bin/wsplgen.exe \ -Dwsplgen.log.output=false \ - -Dartifact.database.dir=\"$DIR/conf\"" -MAINCLASS=org.dive4elements.artifactdatabase.App + -Dlog4j.configuration=file://$FLYSDIR/conf/log4j.properties \ + -Dartifact.database.dir=$FLYSDIR/conf" +export MAINCLASS=org.dive4elements.artifactdatabase.App # For SELinux we need to use 'runuser' not 'su' if [ -x "/sbin/runuser" ]; then SU="/sbin/runuser" else - SU="/bin/su" + SU="/bin/su -m" fi +# pulled from RHEL4 /etc/rc.d/init.d/functions +function checkpid() { + local i + for i in $* ; do + if [ -d "/proc/${i}" ]; then + return 0 + fi + done + return 1 +} + +. /etc/rc.status +rc_reset + +function start() { + echo -n "Starting D4E-river server... " + if [ -f "/var/lock/subsys/${NAME}" ] ; then + if [ -f "/var/run/${NAME}.pid" ]; then + read kpid < /var/run/${NAME}.pid + if checkpid $kpid 2>&1; then + echo "$NAME process already running with pid $kpid" + rc_failed 0 + exit + else + echo "lock file found but no process running for pid $kpid, continuing" + rc_failed 7 + fi + fi + fi + + export D4E_PID="/var/run/${NAME}.pid" + touch $D4E_PID + chown $RUNAS $D4E_PID + touch $LOGFILE + chown $RUNAS $LOGFILE + + for l in `find "$FLYSDIR/bin/lib" -name \*.jar -print`; do + CLASSPATH=$CLASSPATH:$l + done + + export CLASSPATH + + $SU $RUNAS -c "$START_SCRIPT" + #>> $LOGFILE 2>&1 + RETVAL="$?" + if [ "$RETVAL" -eq 0 ]; then + rc_failed 0 + touch /var/lock/subsys/${NAME} + else + rc_failed 7 + fi + rc_status -v +} + +function stop() { + echo -n "Shutting down D4E-River" + if [ -f "/var/lock/subsys/${NAME}" ]; then + count="0" + if [ -f "/var/run/${NAME}.pid" ]; then + read kpid < /var/run/${NAME}.pid + kill $kpid + until [ "$(ps --pid $kpid | grep -c $kpid)" -eq "0" ] || \ + [ "$count" -gt "$SHUTDOWN_WAIT" ]; do + if [ "$SHUTDOWN_VERBOSE" = "true" ]; then + echo -n -e "\nwaiting for processes $kpid to exit" + fi + sleep 1 + let count="${count}+1" + done + if [ "$count" -gt "$SHUTDOWN_WAIT" ]; then + if [ "$SHUTDOWN_VERBOSE" = "true" ]; then + echo -n -e "\nkilling processes which didn't stop" + echo -n -e "after " + echo -n "$SHUTDOWN_WAIT seconds" + fi + kill -9 $kpid + fi + rc_failed 0 + if [ "$count" -gt "0" ]; then + echo -n -e "\n" + fi + fi + rm -f /var/lock/subsys/${NAME} /var/run/${NAME}.pid + fi + rc_status -v +} + + + + case "$1" in start) - echo "Starting D4E-river server..." - $SU - $RUNAS -c "/usr/bin/java -classpath $CLASSPATH $ARGS $MAINCLASS" &> $LOGFILE & - PID=$! - echo $PID > $PIDFILE + start ;; stop) - echo "Stopping D4E-river server..." - PID=`cat $PIDFILE` - STOPRES=0 - while [ $STOPRES -le 0 ] - do - kill -15 $PID &> /dev/null - STOPRES=$? - sleep 1 - done - echo "done." + stop ;; restart) $0 stop && $0 start