Improve OSGi Boot RPM
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 14 Nov 2011 15:51:40 +0000 (15:51 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 14 Nov 2011 15:51:40 +0000 (15:51 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@4906 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

osgi/dist/osgi-boot/pom.xml
osgi/dist/osgi-boot/src/main/rpm/etc/osgiboot/osgi-service-init-functions.sh [new file with mode: 0644]
osgi/dist/osgi-boot/src/main/rpm/usr/sbin/osgi-service
osgi/dist/osgi-boot/src/main/scripts/postinstall [deleted file]
osgi/dist/osgi-boot/src/main/scripts/postremove [deleted file]
osgi/dist/osgi-boot/src/main/scripts/preremove [deleted file]

index 82b194ee9e0617f3d5505224fa8a5dbe4cf19818..952d3bb07adc8a8d74056de11f3e40207933372c 100644 (file)
                                                                                        <username>root</username>
                                                                                        <groupname>root</groupname>
                                                                                        <filemode>644</filemode>
-                                                                                       <configuration>true</configuration>
+                                                                                       <configuration>noreplace</configuration>
+                                                                                       <directoryIncluded>false</directoryIncluded>
                                                                                        <sources>
                                                                                                <source>
                                                                                                        <location>src/main/rpm/etc/osgiboot</location>
                                                                                                        <includes>
-                                                                                                               <include>*</include>
+                                                                                                               <include>*-settings.sh</include>
+                                                                                                       </includes>
+                                                                                               </source>
+                                                                                       </sources>
+                                                                               </mapping>
+                                                                               <mapping>
+                                                                                       <directory>/etc/osgiboot</directory>
+                                                                                       <username>root</username>
+                                                                                       <groupname>root</groupname>
+                                                                                       <filemode>644</filemode>
+                                                                                       <directoryIncluded>false</directoryIncluded>
+                                                                                       <sources>
+                                                                                               <source>
+                                                                                                       <location>src/main/rpm/etc/osgiboot</location>
+                                                                                                       <includes>
+                                                                                                               <include>*-functions.sh</include>
                                                                                                        </includes>
                                                                                                </source>
                                                                                        </sources>
                                                                                        </sources>
                                                                                </mapping>
                                                                        </mappings>
-                                                                       <!-- <postinstallScriptlet> <scriptFile>src/main/scripts/postinstall</scriptFile> 
-                                                                               </postinstallScriptlet> <preremoveScriptlet> <scriptFile>src/main/scripts/preremove</scriptFile> 
-                                                                               </preremoveScriptlet> <postremoveScriptlet> <scriptFile>src/main/scripts/postremove</scriptFile> 
-                                                                               </postremoveScriptlet> -->
                                                                        <requires>
                                                                                <require>java</require>
-                                                                               <!-- For the start/stop scripts <require>telnet</require> <require>expect</require> -->
                                                                        </requires>
                                                                </configuration>
                                                        </execution>
diff --git a/osgi/dist/osgi-boot/src/main/rpm/etc/osgiboot/osgi-service-init-functions.sh b/osgi/dist/osgi-boot/src/main/rpm/etc/osgiboot/osgi-service-init-functions.sh
new file mode 100644 (file)
index 0000000..35bf970
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/bash
+
+# Source function library.
+. /etc/rc.d/init.d/functions
+
+RETVAL=0
+
+osgi_service_start() {
+       APP=$1
+       # create log an run directories writable by the application user
+       USER=$APP
+       GROUP=$APP
+       RUN_DIR=/var/run/$APP
+       LOG_DIR=/var/log/$APP
+       if [ ! -d $LOG_DIR ];then
+               mkdir -m 0750 $LOG_DIR
+               chown -R $USER.$GROUP $LOG_DIR
+       fi
+       if [ ! -d $RUN_DIR ];then
+               mkdir -m 0750 $RUN_DIR
+               chown -R $USER.$GROUP $RUN_DIR
+       fi
+       
+       # call Argeo Commons OSGi utilities as the application user
+       daemon --user $USER /usr/sbin/osgi-service $APP start
+       
+       RETVAL=$?
+       #action $"Start $APP" /bin/true
+       if [ $RETVAL -eq 0 ];then
+               PID=`cat $RUN_DIR/$APP.pid`
+               action $"Started $APP with pid $PID" /bin/true
+       else
+               action $"Could not start $APP" /bin/false
+       fi
+       return $RETVAL
+}
+
+osgi_service_stop() {
+       APP=$1
+       USER=$APP
+       # call Argeo Commons OSGi utilities as the application user
+       runuser -s /bin/bash $USER -c "/usr/sbin/osgi-service $APP stop"
+       RETVAL=$?
+       if [ $RETVAL -eq 0 ];then
+               action $"Stopped $APP" /bin/true
+       else
+               action $"Could not stop $APP" /bin/false
+       fi
+       return $RETVAL
+}
+
+osgi_service_status() {
+       APP=$1
+       USER=$APP
+       # call Argeo Commons OSGi utilities as the application user
+       runuser -s /bin/bash $USER -c "/usr/sbin/osgi-service $APP status"
+       RETVAL=$?
+       return $RETVAL
+}
index 6fbb1e41cdab9d9960e9c99c6733b1cfcd6ac862..c1f4528127d48ab843bd4bbd88f693541e4ef469 100644 (file)
@@ -16,10 +16,11 @@ 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
 
@@ -29,17 +30,24 @@ 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 \
+       $JVM \
                -Dosgi.bundles="org.argeo.osgi.boot.jar@start" \
                -Dargeo.osgi.bundles="$CONF_DIR/modules;in=*,$LIB_DIR;in=*" \
                -Dargeo.osgi.shutdownFile="$SHUTDOWN_FILE" \
@@ -51,15 +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
@@ -69,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
@@ -83,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
diff --git a/osgi/dist/osgi-boot/src/main/scripts/postinstall b/osgi/dist/osgi-boot/src/main/scripts/postinstall
deleted file mode 100644 (file)
index 5254e30..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-#rm -f /usr/share/osgiboot/lib/org.eclipse.osgi.jar
-#ln -vs `ls /usr/share/osgiboot/lib/org.eclipse.osgi-*.jar` /usr/share/osgiboot/lib/org.eclipse.osgi.jar
-
-#rm -f /usr/share/osgiboot/lib/org.argeo.osgi.boot.jar
-#ln -vs `ls /usr/share/osgiboot/lib/org.argeo.osgi.boot-*.jar` /usr/share/osgiboot/lib/org.argeo.osgi.boot.jar
diff --git a/osgi/dist/osgi-boot/src/main/scripts/postremove b/osgi/dist/osgi-boot/src/main/scripts/postremove
deleted file mode 100644 (file)
index 5d0ce38..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-if [ $1 = "0" ];then
-
-fi
diff --git a/osgi/dist/osgi-boot/src/main/scripts/preremove b/osgi/dist/osgi-boot/src/main/scripts/preremove
deleted file mode 100644 (file)
index 872f360..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-if [ $1 = "0" ];then
-       
-fi