]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - osgi/dist/osgi-boot/src/main/rpm/usr/sbin/osgi-service
Improve OSGi Boot RPM
[lgpl/argeo-commons.git] / osgi / dist / osgi-boot / src / main / rpm / usr / sbin / osgi-service
index 7d1ad6e5cd447df9d9579446da11e9d8c551b1e2..c1f4528127d48ab843bd4bbd88f693541e4ef469 100644 (file)
@@ -16,9 +16,11 @@ LIB_DIR=/usr/share/$APP/lib
 EXEC_DIR=/var/lib/$APP
 DATA_DIR=$EXEC_DIR/data
 CONF_RW=$EXEC_DIR/conf
-LOG_FILE=/var/log/$APP.log
 
-RUN_DIR=/var/run
+LOG_DIR=/var/log/$APP
+LOG_FILE=$LOG_DIR/$APP.log
+
+RUN_DIR=/var/run/$APP
 PID_FILE=$RUN_DIR/$APP.pid
 SHUTDOWN_FILE=$RUN_DIR/$APP.shutdown
 
@@ -28,7 +30,21 @@ OSGI_FRAMEWORK=$OSGI_INSTALL_AREA/org.eclipse.osgi.jar
 RETVAL=0
 
 start() {
-       cp $CONF_DIR/config.ini $CONF_RW/config.ini
+       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
        $JVM \
@@ -43,14 +59,24 @@ start() {
                &>> $LOG_FILE &
        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
        rm -f $SHUTDOWN_FILE
@@ -60,13 +86,34 @@ 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
-       echo Stopped $APP with pid $PID
        return $RETVAL
 }
 
-# See how we were called.
+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
+}
+
+# main
 case "$2" in
   start)
         start
@@ -74,20 +121,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