RPM packaging of OSGi boot
authorMathieu Baudier <mbaudier@argeo.org>
Wed, 12 Oct 2011 19:23:16 +0000 (19:23 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Wed, 12 Oct 2011 19:23:16 +0000 (19:23 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@4814 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

osgi/dist/osgi-boot/pom.xml [new file with mode: 0644]
osgi/dist/osgi-boot/src/main/rpm/etc/osgiboot/osgi-service-settings.sh [new file with mode: 0644]
osgi/dist/osgi-boot/src/main/rpm/usr/sbin/osgi-service [new file with mode: 0644]
osgi/dist/osgi-boot/src/main/scripts/postinstall [new file with mode: 0644]
osgi/dist/osgi-boot/src/main/scripts/postremove [new file with mode: 0644]
osgi/dist/osgi-boot/src/main/scripts/preremove [new file with mode: 0644]
osgi/dist/pom.xml [new file with mode: 0644]
osgi/pom.xml
osgi/runtime/org.argeo.osgi.boot/src/main/java/org/argeo/osgi/boot/Activator.java
osgi/runtime/org.argeo.osgi.boot/src/main/java/org/argeo/osgi/boot/AdminThread.java [new file with mode: 0644]

diff --git a/osgi/dist/osgi-boot/pom.xml b/osgi/dist/osgi-boot/pom.xml
new file mode 100644 (file)
index 0000000..ffb38c6
--- /dev/null
@@ -0,0 +1,131 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+       <modelVersion>4.0.0</modelVersion>
+       <parent>
+               <groupId>org.argeo.commons.osgi</groupId>
+               <version>0.3.4-SNAPSHOT</version>
+               <artifactId>dist</artifactId>
+               <relativePath>..</relativePath>
+       </parent>
+       <artifactId>osgi-boot</artifactId>
+       <packaging>pom</packaging>
+       <name>Commons OSGi Boot Distribution</name>
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-dependency-plugin</artifactId>
+                               <executions>
+                                       <execution>
+                                               <id>copy-dependencies</id>
+                                               <phase>package</phase>
+                                               <goals>
+                                                       <goal>copy-dependencies</goal>
+                                               </goals>
+                                               <configuration>
+                                                       <includeTypes>jar</includeTypes>
+                                                       <stripVersion>true</stripVersion>
+                                                       <outputDirectory>${project.build.directory}/lib</outputDirectory>
+                                               </configuration>
+                                       </execution>
+                               </executions>
+                       </plugin>
+                       <plugin>
+                               <groupId>org.codehaus.mojo</groupId>
+                               <artifactId>rpm-maven-plugin</artifactId>
+                               <version>2.1-alpha-1</version>
+                               <extensions>true</extensions>
+                               <configuration>
+                                       <version>${project.version}</version>
+                                       <release>r${buildNumber}.argeo</release>
+                                       <copyright>2011 Argeo</copyright>
+                                       <distribution>argeo</distribution>
+                                       <packager>mbaudier@argeo.org</packager>
+                                       <group>Applications/System</group>
+                                       <prefix>/usr</prefix>
+                               </configuration>
+                               <executions>
+                                       <execution>
+                                               <id>rpm-sdk</id>
+                                               <phase>package</phase>
+                                               <goals>
+                                                       <goal>attached-rpm</goal>
+                                               </goals>
+                                               <configuration>
+                                                       <mappings>
+                                                               <mapping>
+                                                                       <directory>/etc/osgiboot</directory>
+                                                                       <username>root</username>
+                                                                       <groupname>root</groupname>
+                                                                       <filemode>644</filemode>
+                                                                       <configuration>true</configuration>
+                                                                       <sources>
+                                                                               <source>
+                                                                                       <location>src/main/rpm/etc/osgiboot</location>
+                                                                                       <includes>
+                                                                                               <include>*</include>
+                                                                                       </includes>
+                                                                               </source>
+                                                                       </sources>
+                                                               </mapping>
+                                                               <mapping>
+                                                                       <directory>/usr/sbin</directory>
+                                                                       <username>root</username>
+                                                                       <groupname>root</groupname>
+                                                                       <filemode>755</filemode>
+                                                                       <sources>
+                                                                               <source>
+                                                                                       <location>src/main/rpm/usr/sbin</location>
+                                                                                       <includes>
+                                                                                               <include>*</include>
+                                                                                       </includes>
+                                                                               </source>
+                                                                       </sources>
+                                                               </mapping>
+                                                               <mapping>
+                                                                       <directory>/usr/share/osgiboot/lib</directory>
+                                                                       <username>root</username>
+                                                                       <groupname>root</groupname>
+                                                                       <filemode>644</filemode>
+                                                                       <directoryIncluded>false</directoryIncluded>
+                                                                       <sources>
+                                                                               <source>
+                                                                                       <location>${project.build.directory}/lib</location>
+                                                                                       <includes>
+                                                                                               <include>*.jar</include>
+                                                                                       </includes>
+                                                                               </source>
+                                                                       </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>
+                               </executions>
+                       </plugin>
+               </plugins>
+       </build>
+       <dependencies>
+               <dependency>
+                       <groupId>org.argeo.commons.osgi</groupId>
+                       <artifactId>org.argeo.osgi.boot</artifactId>
+                       <version>0.3.4-SNAPSHOT</version>
+               </dependency>
+       </dependencies>
+</project>
diff --git a/osgi/dist/osgi-boot/src/main/rpm/etc/osgiboot/osgi-service-settings.sh b/osgi/dist/osgi-boot/src/main/rpm/etc/osgiboot/osgi-service-settings.sh
new file mode 100644 (file)
index 0000000..f5504f8
--- /dev/null
@@ -0,0 +1 @@
+#JAVA_OPTS=-Xmx256m
\ No newline at end of file
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
new file mode 100644 (file)
index 0000000..cbaecf5
--- /dev/null
@@ -0,0 +1,80 @@
+#!/bin/sh
+
+JVM=java
+. /etc/osgiboot/osgi-service-settings.sh
+
+APP=$1
+
+CONF_DIR=/etc/$APP
+if [ -f $CONF_DIR/settings.sh ];then
+       . $CONF_DIR/settings.sh
+fi
+
+LIB_DIR=/usr/share/$APP/lib
+
+# read/write
+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
+PID_FILE=$RUN_DIR/$APP.pid
+SHUTDOWN_FILE=$RUN_DIR/$APP.shutdown
+
+OSGI_INSTALL_AREA=/usr/share/osgiboot/lib
+OSGI_FRAMEWORK=$OSGI_INSTALL_AREA/org.eclipse.osgi.jar
+
+RETVAL=0
+
+start() {
+       cp $CONF_DIR/config.ini $CONF_RW/config.ini
+       touch $SHUTDOWN_FILE
+       cd $EXEC_DIR && $JVM \
+               -Dosgi.bundles="org.argeo.osgi.boot.jar@start" \
+               -Dargeo.osgi.bundles="$CONF_DIR/modules;in=*,$LIB_DIR;in=*" \
+               -Dlog4j.configuration="file:$CONF_DIR/log4j.properties" \
+               $JAVA_OPTS -jar $OSGI_FRAMEWORK \
+               -configuration "$CONF_RW" \
+               -data "$DATA_DIR" \
+               &> $LOG_FILE &
+       PID=$!
+       echo $PID > $PID_FILE
+       echo Started $APP with pid $PID
+       return $RETVAL
+}
+
+stop() {
+       PID=`cat $PID_FILE`
+       rm -f $SHUTDOWN_FILE
+       # TODO wait for process to finish until timeout, then kill
+       echo Stopped $APP with pid $PID
+       return $RETVAL
+}
+
+# See how we were called.
+case "$2" in
+  start)
+        start
+        ;;
+  stop)
+        stop
+        ;;
+  restart|reload)
+        stop
+        sleep 10
+        start
+        RETVAL=$?
+        ;;
+  condrestart)
+               echo Not implemented
+               exit 1
+        ;;
+  status)
+               echo Not implemented
+               exit 1
+        ;;
+  *)
+        echo $"Usage: $0 {start|stop|restart}"
+        exit 1
+esac
diff --git a/osgi/dist/osgi-boot/src/main/scripts/postinstall b/osgi/dist/osgi-boot/src/main/scripts/postinstall
new file mode 100644 (file)
index 0000000..5254e30
--- /dev/null
@@ -0,0 +1,5 @@
+#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
new file mode 100644 (file)
index 0000000..5d0ce38
--- /dev/null
@@ -0,0 +1,3 @@
+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
new file mode 100644 (file)
index 0000000..872f360
--- /dev/null
@@ -0,0 +1,3 @@
+if [ $1 = "0" ];then
+       
+fi
diff --git a/osgi/dist/pom.xml b/osgi/dist/pom.xml
new file mode 100644 (file)
index 0000000..3bc9421
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+       <modelVersion>4.0.0</modelVersion>
+       <parent>
+               <groupId>org.argeo.commons</groupId>
+               <version>0.3.4-SNAPSHOT</version>
+               <artifactId>osgi</artifactId>
+               <relativePath>..</relativePath>
+       </parent>
+       <groupId>org.argeo.commons.osgi</groupId>
+       <artifactId>dist</artifactId>
+       <name>Commons OSGi Distributions</name>
+       <packaging>pom</packaging>
+       <modules>
+               <module>osgi-boot</module>
+       </modules>
+</project>
\ No newline at end of file
index 5fb919ac2e89255da0c9d71ce20a217c14597842..0d511b9a27faed611367778c71181f28363f09d8 100644 (file)
@@ -14,5 +14,6 @@
                <module>runtime</module>
                <module>plugins</module>
                <module>dep</module>
+               <module>dist</module>
        </modules>
 </project>
\ No newline at end of file
index 9eecf6cbd3fccc4d80dbb4282b68febbd72349e4..1d09d57a00141f6df863b122ed865ceeac3c8083 100644 (file)
@@ -26,7 +26,12 @@ import org.osgi.framework.BundleContext;
  */
 public class Activator implements BundleActivator {
 
-       public void start(BundleContext bundleContext) throws Exception {
+       public void start(final BundleContext bundleContext) throws Exception {
+               // admin thread
+               Thread adminThread = new AdminThread(bundleContext);
+               adminThread.start();
+
+               // bootstrap
                OsgiBoot osgiBoot = new OsgiBoot(bundleContext);
                osgiBoot.bootstrap();
        }
diff --git a/osgi/runtime/org.argeo.osgi.boot/src/main/java/org/argeo/osgi/boot/AdminThread.java b/osgi/runtime/org.argeo.osgi.boot/src/main/java/org/argeo/osgi/boot/AdminThread.java
new file mode 100644 (file)
index 0000000..b0144a9
--- /dev/null
@@ -0,0 +1,53 @@
+package org.argeo.osgi.boot;
+
+import java.io.File;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.launch.Framework;
+
+/** Monitors the runtime and can shut it down. */
+public class AdminThread extends Thread {
+       public final static String PROP_ARGEO_OSGI_SHUTDOWN_FILE = "argeo.osgi.shutdownFile";
+       private File shutdownFile;
+       private final BundleContext bundleContext;
+
+       public AdminThread(BundleContext bundleContext) {
+               super("OSGi Boot Admin");
+               this.bundleContext = bundleContext;
+               if (System.getProperty(PROP_ARGEO_OSGI_SHUTDOWN_FILE) != null) {
+                       shutdownFile = new File(
+                                       System.getProperty(PROP_ARGEO_OSGI_SHUTDOWN_FILE));
+                       if (!shutdownFile.exists()) {
+                               shutdownFile = null;
+                               OsgiBootUtils.warn("Shutdown file " + shutdownFile
+                                               + " not found, feature deactivated");
+                       }
+               }
+       }
+
+       public void run() {
+               if (shutdownFile != null) {
+                       // wait for file to be removed
+                       while (shutdownFile.exists()) {
+                               try {
+                                       Thread.sleep(1000);
+                               } catch (InterruptedException e) {
+                                       e.printStackTrace();
+                               }
+                       }
+
+                       Framework framework = (Framework) bundleContext.getBundle(0);
+                       try {
+                               // shutdown framework
+                               framework.stop();
+                               // wait 10 mins for shutdown
+                               framework.waitForStop(10 * 60 * 1000);
+                               // close VM
+                               System.exit(0);
+                       } catch (Exception e) {
+                               e.printStackTrace();
+                               System.exit(1);
+                       }
+               }
+       }
+}