From: Mathieu Baudier Date: Tue, 17 Jul 2012 12:34:05 +0000 (+0000) Subject: Move to Commons Base X-Git-Tag: argeo-commons-2.1.30~880 X-Git-Url: https://git.argeo.org/?a=commitdiff_plain;h=5726aa10afa99c0b21a9ff5c5f9c5e47fc028164;p=lgpl%2Fargeo-commons.git Move to Commons Base git-svn-id: https://svn.argeo.org/commons/trunk@5482 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/base/dist/osgi-boot/pom.xml b/base/dist/osgi-boot/pom.xml new file mode 100644 index 000000000..069c8baf8 --- /dev/null +++ b/base/dist/osgi-boot/pom.xml @@ -0,0 +1,189 @@ + + 4.0.0 + + org.argeo.commons.osgi + 1.1.4-SNAPSHOT + dist + .. + + osgi-boot + pom + Commons OSGi Boot Distribution + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + package + + copy-dependencies + + + jar + true + ${project.build.directory}/lib + + + + + + + + + org.argeo.commons.osgi + org.argeo.osgi.boot + 1.1.4-SNAPSHOT + + + + + rpmbuild + + + + org.codehaus.mojo + rpm-maven-plugin + + + rpm-osgi-boot + package + + rpm + + + osgi-boot + 2011 Argeo + + + /etc/osgiboot + root + root + 644 + noreplace + false + + + src/main/rpm/etc/osgiboot + + *-settings.sh + + + + + + /etc/osgiboot + root + root + 644 + false + + + src/main/rpm/etc/osgiboot + + *-functions.sh + + + + + + /usr/sbin + root + root + 755 + + + src/main/rpm/usr/sbin + + + + + /usr/share/osgi/boot + root + root + 644 + false + + + ${project.build.directory}/lib + + org.argeo.osgi.boot.jar + + + + + + + osgi-boot-equinox + + + + + + + maven-antrun-plugin + + + install + + run + + + + + + + + + + + + + + + + + rpmbuild-tp + + + + org.codehaus.mojo + rpm-maven-plugin + + + rpm-osgi-boot-equinox + package + + rpm + + + osgi-boot-equinox + ${version.argeo-distribution} + + + /usr/share/osgi/boot + root + root + 644 + false + + + ${project.build.directory}/lib + + org.eclipse.osgi.jar + + + + + + + + + + + + + + diff --git a/base/dist/osgi-boot/src/main/rpm/etc/osgiboot/osgi-service-init-functions.sh b/base/dist/osgi-boot/src/main/rpm/etc/osgiboot/osgi-service-init-functions.sh new file mode 100644 index 000000000..35bf9703f --- /dev/null +++ b/base/dist/osgi-boot/src/main/rpm/etc/osgiboot/osgi-service-init-functions.sh @@ -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 +} diff --git a/base/dist/osgi-boot/src/main/rpm/etc/osgiboot/osgi-service-settings.sh b/base/dist/osgi-boot/src/main/rpm/etc/osgiboot/osgi-service-settings.sh new file mode 100644 index 000000000..f5504f811 --- /dev/null +++ b/base/dist/osgi-boot/src/main/rpm/etc/osgiboot/osgi-service-settings.sh @@ -0,0 +1 @@ +#JAVA_OPTS=-Xmx256m \ No newline at end of file diff --git a/base/dist/osgi-boot/src/main/rpm/usr/sbin/osgi-service b/base/dist/osgi-boot/src/main/rpm/usr/sbin/osgi-service new file mode 100644 index 000000000..5c37f9c82 --- /dev/null +++ b/base/dist/osgi-boot/src/main/rpm/usr/sbin/osgi-service @@ -0,0 +1,153 @@ +#!/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_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 + +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 + + cp --preserve $CONF_DIR/config.ini $CONF_RW/config.ini + touch $SHUTDOWN_FILE + cd $EXEC_DIR + $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 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 + 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 + + # 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 "$2" in + start) + start + ;; + stop) + stop + ;; + status) + status + ;; + *) + echo $"Usage: $0 {start|stop|status}" + exit 1 +esac \ No newline at end of file diff --git a/base/dist/pom.xml b/base/dist/pom.xml new file mode 100644 index 000000000..48b81a258 --- /dev/null +++ b/base/dist/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + org.argeo.commons + 1.1.4-SNAPSHOT + osgi + .. + + org.argeo.commons.osgi + dist + Commons OSGi Distributions + pom + + osgi-boot + + \ No newline at end of file diff --git a/osgi/dist/osgi-boot/pom.xml b/osgi/dist/osgi-boot/pom.xml deleted file mode 100644 index 069c8baf8..000000000 --- a/osgi/dist/osgi-boot/pom.xml +++ /dev/null @@ -1,189 +0,0 @@ - - 4.0.0 - - org.argeo.commons.osgi - 1.1.4-SNAPSHOT - dist - .. - - osgi-boot - pom - Commons OSGi Boot Distribution - - - - org.apache.maven.plugins - maven-dependency-plugin - - - copy-dependencies - package - - copy-dependencies - - - jar - true - ${project.build.directory}/lib - - - - - - - - - org.argeo.commons.osgi - org.argeo.osgi.boot - 1.1.4-SNAPSHOT - - - - - rpmbuild - - - - org.codehaus.mojo - rpm-maven-plugin - - - rpm-osgi-boot - package - - rpm - - - osgi-boot - 2011 Argeo - - - /etc/osgiboot - root - root - 644 - noreplace - false - - - src/main/rpm/etc/osgiboot - - *-settings.sh - - - - - - /etc/osgiboot - root - root - 644 - false - - - src/main/rpm/etc/osgiboot - - *-functions.sh - - - - - - /usr/sbin - root - root - 755 - - - src/main/rpm/usr/sbin - - - - - /usr/share/osgi/boot - root - root - 644 - false - - - ${project.build.directory}/lib - - org.argeo.osgi.boot.jar - - - - - - - osgi-boot-equinox - - - - - - - maven-antrun-plugin - - - install - - run - - - - - - - - - - - - - - - - - rpmbuild-tp - - - - org.codehaus.mojo - rpm-maven-plugin - - - rpm-osgi-boot-equinox - package - - rpm - - - osgi-boot-equinox - ${version.argeo-distribution} - - - /usr/share/osgi/boot - root - root - 644 - false - - - ${project.build.directory}/lib - - org.eclipse.osgi.jar - - - - - - - - - - - - - - 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 deleted file mode 100644 index 35bf9703f..000000000 --- a/osgi/dist/osgi-boot/src/main/rpm/etc/osgiboot/osgi-service-init-functions.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/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 -} 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 deleted file mode 100644 index f5504f811..000000000 --- a/osgi/dist/osgi-boot/src/main/rpm/etc/osgiboot/osgi-service-settings.sh +++ /dev/null @@ -1 +0,0 @@ -#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 deleted file mode 100644 index 5c37f9c82..000000000 --- a/osgi/dist/osgi-boot/src/main/rpm/usr/sbin/osgi-service +++ /dev/null @@ -1,153 +0,0 @@ -#!/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_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 - -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 - - cp --preserve $CONF_DIR/config.ini $CONF_RW/config.ini - touch $SHUTDOWN_FILE - cd $EXEC_DIR - $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 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 - 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 - - # 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 "$2" in - start) - start - ;; - stop) - stop - ;; - status) - status - ;; - *) - echo $"Usage: $0 {start|stop|status}" - exit 1 -esac \ No newline at end of file diff --git a/osgi/dist/pom.xml b/osgi/dist/pom.xml deleted file mode 100644 index 48b81a258..000000000 --- a/osgi/dist/pom.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - 4.0.0 - - org.argeo.commons - 1.1.4-SNAPSHOT - osgi - .. - - org.argeo.commons.osgi - dist - Commons OSGi Distributions - pom - - osgi-boot - - \ No newline at end of file