]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - dist/argeo-node/rpm/usr/sbin/argeoctl
Use 'argeo' instead of 'node' as app name (in order to avoid conflicts
[lgpl/argeo-commons.git] / dist / argeo-node / rpm / usr / sbin / argeoctl
diff --git a/dist/argeo-node/rpm/usr/sbin/argeoctl b/dist/argeo-node/rpm/usr/sbin/argeoctl
new file mode 100755 (executable)
index 0000000..ccadd8e
--- /dev/null
@@ -0,0 +1,129 @@
+#!/bin/sh
+APP=argeo
+
+JVM=java
+
+# Directories and files
+CONF_DIR=/etc/$APP
+CONF_DIRS=/etc/$APP/conf.d
+BASE_POLICY_ALL=/usr/share/$APP/all.policy
+BASE_CONFIG_INI=/usr/share/$APP/config.ini
+
+EXEC_DIR=/var/lib/$APP
+DATA_DIR=$EXEC_DIR/data
+CONF_RW=$EXEC_DIR/state
+CONFIG_INI=$CONF_RW/config.ini
+
+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() {
+       mkdir -p $CONF_RW
+       mkdir -p $DATA_DIR
+
+    # Merge config files
+    printf "## Equinox configuration - Generated by /usr/sbin/nodectl ##\n\n" > $CONFIG_INI
+    cat $BASE_CONFIG_INI >> $CONFIG_INI
+    printf "\n##\n## $CONF_DIR/$APP.ini\n##\n\n" >> $CONFIG_INI
+    cat $CONF_DIR/$APP.ini >> $CONFIG_INI
+    for file in `ls -v $CONF_DIRS/*.ini`; do
+            printf "\n##\n## $file\n##\n\n" >> $CONFIG_INI
+            cat $file >> $CONFIG_INI
+    done;
+
+       cd $EXEC_DIR
+       $JVM \
+               -Dlog4j.configuration="file:$CONF_DIR/log4j.properties" \
+               $JAVA_OPTS -jar $OSGI_FRAMEWORK \
+               -configuration "$CONF_RW" \
+               -data "$DATA_DIR"
+}
+
+reload() {
+       echo Not yet implemented
+}
+
+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
+       kill $PID
+       
+       # wait 10 min for application to shutdown, then kill it
+       TIMEOUT=$((10*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
+}
+
+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
+        ;;
+  reload)
+        reload
+        ;;
+  stop)
+        stop
+        ;;
+  status)
+       status
+        ;;
+  *)
+        echo $"Usage: $0 {start|stop|status}"
+        exit 1
+esac
\ No newline at end of file