Introduce argeo-node RPM packaging
authormbaudier <mbaudier@mostar>
Thu, 26 Oct 2017 21:38:43 +0000 (23:38 +0200)
committermbaudier <mbaudier@mostar>
Thu, 26 Oct 2017 21:38:43 +0000 (23:38 +0200)
dist/argeo-node/.gitignore [new file with mode: 0644]
dist/argeo-node/pom.xml [new file with mode: 0644]
dist/argeo-node/rpm/etc/node/config.ini [new file with mode: 0644]
dist/argeo-node/rpm/etc/node/log4j.properties [new file with mode: 0644]
dist/argeo-node/rpm/etc/node/node.policy [new file with mode: 0644]
dist/argeo-node/rpm/scripts/preinstall [new file with mode: 0644]
dist/argeo-node/rpm/usr/lib/systemd/system/node.service [new file with mode: 0644]
dist/argeo-node/rpm/usr/sbin/node-service [new file with mode: 0755]
dist/pom.xml

diff --git a/dist/argeo-node/.gitignore b/dist/argeo-node/.gitignore
new file mode 100644 (file)
index 0000000..b83d222
--- /dev/null
@@ -0,0 +1 @@
+/target/
diff --git a/dist/argeo-node/pom.xml b/dist/argeo-node/pom.xml
new file mode 100644 (file)
index 0000000..e53a115
--- /dev/null
@@ -0,0 +1,90 @@
+<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>2.1.70-SNAPSHOT</version>
+               <artifactId>dist</artifactId>
+               <relativePath>..</relativePath>
+       </parent>
+       <artifactId>argeo-node</artifactId>
+       <packaging>pom</packaging>
+       <name>Argeo Node</name>
+       <profiles>
+               <profile>
+                       <id>rpmbuild</id>
+                       <build>
+                               <plugins>
+                                       <plugin>
+                                               <groupId>org.codehaus.mojo</groupId>
+                                               <artifactId>rpm-maven-plugin</artifactId>
+                                               <executions>
+                                                       <execution>
+                                                               <id>rpm-node</id>
+                                                               <phase>package</phase>
+                                                               <goals>
+                                                                       <goal>rpm</goal>
+                                                               </goals>
+                                                               <configuration>
+                                                                       <name>argeo-node</name>
+                                                                       <mappings>
+                                                                               <mapping>
+                                                                                       <directory>/etc/node</directory>
+                                                                                       <username>root</username>
+                                                                                       <groupname>node</groupname>
+                                                                                       <filemode>640</filemode>
+                                                                                       <configuration>noreplace</configuration>
+                                                                                       <directoryIncluded>false</directoryIncluded>
+                                                                                       <sources>
+                                                                                               <source>
+                                                                                                       <location>rpm/etc/node</location>
+                                                                                               </source>
+                                                                                       </sources>
+                                                                               </mapping>
+                                                                               <mapping>
+                                                                                       <directory>/usr/lib/systemd/system</directory>
+                                                                                       <username>root</username>
+                                                                                       <groupname>root</groupname>
+                                                                                       <filemode>644</filemode>
+                                                                                       <directoryIncluded>false</directoryIncluded>
+                                                                                       <sources>
+                                                                                               <source>
+                                                                                                       <location>rpm/usr/lib/systemd/system</location>
+                                                                                                       <includes>
+                                                                                                               <include>*.service</include>
+                                                                                                       </includes>
+                                                                                               </source>
+                                                                                       </sources>
+                                                                               </mapping>
+                                                                               <mapping>
+                                                                                       <directory>/usr/sbin</directory>
+                                                                                       <username>root</username>
+                                                                                       <groupname>root</groupname>
+                                                                                       <filemode>755</filemode>
+                                                                                       <directoryIncluded>false</directoryIncluded>
+                                                                                       <sources>
+                                                                                               <source>
+                                                                                                       <location>rpm/usr/sbin</location>
+                                                                                                       <includes>
+                                                                                                               <include>node-service</include>
+                                                                                                       </includes>
+                                                                                               </source>
+                                                                                       </sources>
+                                                                               </mapping>
+                                                                       </mappings>
+                                                                       <preinstallScriptlet>
+                                                                               <scriptFile>rpm/scripts/preinstall</scriptFile>
+                                                                       </preinstallScriptlet>
+                                                                       <requires>
+<!--                                                                           <require>argeo-cms-platform</require> -->
+                                                                               <require>osgi-boot</require>
+                                                                               <!-- do not explicitely require java -->
+                                                                       </requires>
+                                                               </configuration>
+                                                       </execution>
+                                               </executions>
+                                       </plugin>
+                               </plugins>
+                       </build>
+               </profile>
+       </profiles>
+</project>
diff --git a/dist/argeo-node/rpm/etc/node/config.ini b/dist/argeo-node/rpm/etc/node/config.ini
new file mode 100644 (file)
index 0000000..44a2170
--- /dev/null
@@ -0,0 +1,40 @@
+#argeo.osgi.baseUrl=http://forge.argeo.org/data/java/argeo-2.1/
+#argeo.osgi.distributionUrl=org/argeo/commons/org.argeo.dep.cms.sdk/2.1.65/org.argeo.dep.cms.sdk-2.1.69.jar
+argeo.osgi.bundles=\
+/usr/local/share/osgi;in=**/*.jar,\
+/usr/share/osgi;in=**/*.jar
+
+argeo.osgi.boot.debug=true
+
+argeo.osgi.start.2.node=\
+org.eclipse.equinox.http.servlet,\
+org.eclipse.equinox.http.jetty,\
+org.eclipse.equinox.metatype,\
+org.eclipse.equinox.cm,\
+org.eclipse.rap.rwt.osgi
+
+argeo.osgi.start.3.node=\
+org.argeo.cms
+
+argeo.osgi.start.4.apps=\
+org.eclipse.gemini.blueprint.extender
+
+argeo.osgi.start.4.workbench=\
+org.eclipse.equinox.http.registry,\
+
+argeo.node.repo.type=h2
+org.osgi.service.http.port=8080
+
+# DO NOT CHANGE BELOW UNLESS YOU KNOW WHAT YOU ARE DOING
+osgi.bundles=org.argeo.osgi.boot.jar@start
+org.osgi.framework.bootdelegation=com.sun.jndi.ldap,\
+com.sun.jndi.ldap.sasl,\
+com.sun.security.jgss,\
+com.sun.jndi.dns,\
+com.sun.nio.file,\
+com.sun.nio.sctp
+
+eclipse.ignoreApp=true
+osgi.noShutdown=true
+org.eclipse.equinox.http.jetty.autostart=false
+org.eclipse.rap.workbenchAutostart=false
diff --git a/dist/argeo-node/rpm/etc/node/log4j.properties b/dist/argeo-node/rpm/etc/node/log4j.properties
new file mode 100644 (file)
index 0000000..f79dc2c
--- /dev/null
@@ -0,0 +1,13 @@
+log4j.rootLogger=WARN, console
+
+log4j.logger.org.argeo=DEBUG
+
+## Appenders
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern= %-5p %d{ISO8601} %m - %c - [%t]%n
+
+log4j.appender.file=org.apache.log4j.RollingFileAppender
+log4j.appender.file.File=/var/log/node/node.log
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern= %-5p %d{ISO8601} [%15.15t] %m - %c%n
diff --git a/dist/argeo-node/rpm/etc/node/node.policy b/dist/argeo-node/rpm/etc/node/node.policy
new file mode 100644 (file)
index 0000000..facb613
--- /dev/null
@@ -0,0 +1,3 @@
+grant {
+  permission java.security.AllPermission;
+};
\ No newline at end of file
diff --git a/dist/argeo-node/rpm/scripts/preinstall b/dist/argeo-node/rpm/scripts/preinstall
new file mode 100644 (file)
index 0000000..cff6bd4
--- /dev/null
@@ -0,0 +1,17 @@
+if [ $1 = "1" ];then
+       APP=node
+       
+       # check if user exists
+       /bin/id $APP 2>/dev/null
+       if [ $? -ne 0 ];then
+               echo Create user $APP...
+               useradd --system --home-dir /var/lib/$APP --shell /bin/bash --user-group --create-home $APP
+       fi
+       
+       mkdir -p /var/lib/$APP/{state,data,indexes}
+       chown $APP.$APP /var/lib/$APP/{state,data,indexes}
+       mkdir -p /var/run/$APP
+       chown $APP.$APP /var/run/$APP
+       mkdir -p /var/log/$APP
+       chown $APP.$APP /var/log/$APP
+fi
\ No newline at end of file
diff --git a/dist/argeo-node/rpm/usr/lib/systemd/system/node.service b/dist/argeo-node/rpm/usr/lib/systemd/system/node.service
new file mode 100644 (file)
index 0000000..45fab9a
--- /dev/null
@@ -0,0 +1,15 @@
+[Unit]
+Description=Argeo Node
+After=network.target
+Wants=postgresql.service
+
+[Service]
+Type=simple
+PIDFile=/var/run/node/node.pid
+ExecStart=/usr/sbin/node-service start
+#ExecReload=/usr/sbin/node-service reload
+#ExecStop=/usr/sbin/node-service stop
+SuccessExitStatus=143
+
+[Install]
+WantedBy=multi-user.target
diff --git a/dist/argeo-node/rpm/usr/sbin/node-service b/dist/argeo-node/rpm/usr/sbin/node-service
new file mode 100755 (executable)
index 0000000..7accca9
--- /dev/null
@@ -0,0 +1,146 @@
+#!/bin/sh
+APP=node
+
+JVM=java
+
+# Directories and files
+CONF_DIR=/etc/$APP
+
+EXEC_DIR=/var/lib/$APP
+DATA_DIR=$EXEC_DIR/data
+CONF_RW=$EXEC_DIR/state
+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
+
+OSGI_INSTALL_AREA=/usr/share/osgi/boot
+OSGI_FRAMEWORK=$OSGI_INSTALL_AREA/org.eclipse.osgi.jar
+
+# Overwrite variables
+if [ -f $CONF_DIR/settings.sh ];then
+       . $CONF_DIR/settings.sh
+fi
+
+RETVAL=0
+
+start() {
+       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
+
+       if [ ! -f $CONF_RW/config.ini ]; then
+               cp --preserve $CONF_DIR/config.ini $CONF_RW/config.ini
+       fi
+       touch $SHUTDOWN_FILE
+       cd $EXEC_DIR
+       $JVM \
+               -Dargeo.osgi.shutdownFile="$SHUTDOWN_FILE" \
+               -Dlog4j.configuration="file:$CONF_DIR/log4j.properties" \
+               -Djava.security.manager= \
+               -Djava.security.policy="file:$CONF_DIR/node.policy" \
+               $JAVA_OPTS -jar $OSGI_FRAMEWORK \
+               -configuration "$CONF_RW" \
+               -data "$DATA_DIR"
+}
+
+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
+       
+       # 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
+       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
+}
+
+# main
+case "$1" in
+  start)
+        start
+        ;;
+  stop)
+        stop
+        ;;
+  status)
+       status
+        ;;
+  *)
+        echo $"Usage: $0 {start|stop|status}"
+        exit 1
+esac
\ No newline at end of file
index ff86624e7fe678d11653579a10db6069716ab250..b7d0ab0cd5ccfe74e653b4843f6f0426c4e299f5 100644 (file)
@@ -12,5 +12,6 @@
        <packaging>pom</packaging>
        <modules>
                <module>osgi-boot</module>
+               <module>argeo-node</module>
        </modules>
 </project>
\ No newline at end of file