X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=osgi%2Fdist%2Fosgi-boot%2Fsrc%2Fmain%2Frpm%2Fusr%2Fsbin%2Fosgi-service;h=5c37f9c82f028dd9137559fc03a7fa6b111559ec;hb=36862e777231ee8beecf4d5c7081fdfb8e28cfbd;hp=6fbb1e41cdab9d9960e9c99c6733b1cfcd6ac862;hpb=ed37ad5f3228e19d75cda12e366ccdc05170fbe4;p=lgpl%2Fargeo-commons.git diff --git a/osgi/dist/osgi-boot/src/main/rpm/usr/sbin/osgi-service b/osgi/dist/osgi-boot/src/main/rpm/usr/sbin/osgi-service index 6fbb1e41c..5c37f9c82 100644 --- a/osgi/dist/osgi-boot/src/main/rpm/usr/sbin/osgi-service +++ b/osgi/dist/osgi-boot/src/main/rpm/usr/sbin/osgi-service @@ -16,66 +16,127 @@ LIB_DIR=/usr/share/$APP/lib EXEC_DIR=/var/lib/$APP DATA_DIR=$EXEC_DIR/data CONF_RW=$EXEC_DIR/conf + LOG_DIR=/var/log/$APP LOG_FILE=$LOG_DIR/$APP.log -RUN_DIR=/var/run +RUN_DIR=/var/run/$APP PID_FILE=$RUN_DIR/$APP.pid SHUTDOWN_FILE=$RUN_DIR/$APP.shutdown -OSGI_INSTALL_AREA=/usr/share/osgiboot/lib +OSGI_INSTALL_AREA=/usr/share/osgi/boot OSGI_FRAMEWORK=$OSGI_INSTALL_AREA/org.eclipse.osgi.jar RETVAL=0 start() { - if [ ! -d $LOG_DIR ];then - mkdir -m 0750 -p $LOG_DIR - touch $LOG_FILE - chown -R $APP.$APP $LOG_DIR + if [ -f $PID_FILE ];then + PID=`cat $PID_FILE` + kill -0 $PID &> /dev/null + PID_EXISTS=$? + if [ $PID_EXISTS -eq 0 ]; then + echo $APP already running with pid $PID + RETVAL=1 + return $RETVAL + else + echo Old $APP process with pid $PID is dead, removing $PID_FILE + rm -f $PID_FILE + fi fi cp --preserve $CONF_DIR/config.ini $CONF_RW/config.ini touch $SHUTDOWN_FILE cd $EXEC_DIR - # start as user $APP - sudo -u $APP $JVM \ - -Dosgi.bundles="org.argeo.osgi.boot.jar@start" \ - -Dargeo.osgi.bundles="$CONF_DIR/modules;in=*,$LIB_DIR;in=*" \ + $JVM \ -Dargeo.osgi.shutdownFile="$SHUTDOWN_FILE" \ -Dlog4j.configuration="file:$CONF_DIR/log4j.properties" \ $JAVA_OPTS -jar $OSGI_FRAMEWORK \ -clean \ -configuration "$CONF_RW" \ -data "$DATA_DIR" \ - &>> $LOG_FILE & + >> $LOG_FILE 2>&1 & + # (above) stderr redirected to stdout, then stdout to log file + # see http://tldp.org/LDP/abs/html/io-redirection.html PID=$! echo $PID > $PID_FILE - echo Started $APP with pid $PID + #echo Started $APP with pid $PID return $RETVAL } stop() { if [ -f $PID_FILE ];then PID=`cat $PID_FILE` + kill -0 $PID &> /dev/null + PID_EXISTS=$? + if [ $PID_EXISTS -ne 0 ]; then + echo Dead $APP process with pid $PID, removing $PID_FILE + rm -f $PID_FILE + RETVAL=1 + return $RETVAL + fi else echo $APP is not running + RETVAL=1 return $RETVAL fi + + # notifies application by removing the shutdown file rm -f $SHUTDOWN_FILE - timeout 5m sh << EOF -while kill -0 $PID &> /dev/null; do sleep 1; done -EOF - TIMEOUT_EXIT=$? - if [ $TIMEOUT_EXIT -eq 124 ];then - kill -9 $PID - fi + + # wait 5 min for application to shutdown, then kill it + TIMEOUT=$((5*60)) + BEGIN=$(date +%s) + while kill -0 $PID &> /dev/null + do + sleep 1 + NOW=$(date +%s) + DURATION=$(($NOW-$BEGIN)) + if [ $DURATION -gt $TIMEOUT ]; then + kill -9 $PID + echo Forcibly killed $APP with pid $PID + RETVAL=1 + fi + done + + # remove pid file rm -f $PID_FILE - echo Stopped $APP with pid $PID + return $RETVAL + +# timeout is only available in EL6 +# timeout 5m sh << EOF +#while kill -0 $PID &> /dev/null; do sleep 1; done +#EOF +# TIMEOUT_EXIT=$? +# if [ $TIMEOUT_EXIT -eq 124 ];then +# kill -9 $PID +# RETVAL=1 +# echo Killed $APP with pid $PID +# else +# echo Stopped $APP with pid $PID +# fi +# rm -f $PID_FILE +# return $RETVAL +} + +status() { + if [ -f $PID_FILE ];then + PID=`cat $PID_FILE` + else + echo $APP is not running + return $RETVAL + fi + kill -0 $PID &> /dev/null + PID_EXISTS=$? + if [ $PID_EXISTS -eq 0 ]; then + echo $APP is running with pid $PID ... + else + echo No $APP process with pid $PID, removing $PID_FILE + rm -f $PID_FILE + fi return $RETVAL } -# See how we were called. +# main case "$2" in start) start @@ -83,20 +144,10 @@ case "$2" in stop) stop ;; - restart) - stop - start - RETVAL=$? - ;; status) - if [ -f $PID_FILE ];then - PID=`cat $PID_FILE` - echo $APP is running with pid $PID ... - else - echo $APP is not running - fi + status ;; *) - echo $"Usage: $0 {start|stop|restart|status}" + echo $"Usage: $0 {start|stop|status}" exit 1 esac \ No newline at end of file