X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=dist%2Fargeo-node%2Frpm%2Fusr%2Fsbin%2Fnodectl;fp=dist%2Fargeo-node%2Frpm%2Fusr%2Fsbin%2Fnodectl;h=26fe3eeafda7e3513894140ed12efbafa83cdddb;hb=5b5c2b97eee9edd037e198acadf8b416a973863f;hp=0000000000000000000000000000000000000000;hpb=3200c28bdc2f274178a62a372dbd2f2cd12855ed;p=lgpl%2Fargeo-commons.git diff --git a/dist/argeo-node/rpm/usr/sbin/nodectl b/dist/argeo-node/rpm/usr/sbin/nodectl new file mode 100755 index 000000000..26fe3eeaf --- /dev/null +++ b/dist/argeo-node/rpm/usr/sbin/nodectl @@ -0,0 +1,152 @@ +#!/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 \ + -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" +} + +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 + + # 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 + +# 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 + ;; + reload) + reload + ;; + stop) + stop + ;; + status) + status + ;; + *) + echo $"Usage: $0 {start|stop|status}" + exit 1 +esac \ No newline at end of file