Make new systemd units more robust.
authorMathieu Baudier <mbaudier@argeo.org>
Wed, 29 Apr 2020 09:05:34 +0000 (11:05 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Wed, 29 Apr 2020 09:05:34 +0000 (11:05 +0200)
dist/argeo-node/rpm/usr/lib/systemd/system/argeo.service
dist/argeo-node/rpm/usr/lib/systemd/system/argeo@.service
dist/argeo-node/rpm/usr/lib/systemd/user/argeo@.service
dist/argeo-node/rpm/usr/sbin/argeoctl

index f30e9fb2ec920c241f56b2c6d90f787e520afde8..8d8c261d7700beb72a9792f99b0d38029c027827 100644 (file)
@@ -1,14 +1,12 @@
 [Unit]
-Description=Argeo Node
+Description=Argeo default node
 After=network.target
 Wants=postgresql.service
 
 [Service]
 Type=simple
-PIDFile=/var/run/argeo/argeo.pid
 ExecStart=/usr/sbin/argeoctl start
 ExecReload=/usr/sbin/argeoctl reload
-SuccessExitStatus=143
 
 [Install]
 WantedBy=multi-user.target
index d76f7424a0ea76e30e9a3670d96c5bb73e4c5a18..14c2ecdb3ab9ed1ae6ff01c6013961072bbb6c8d 100644 (file)
@@ -1,18 +1,21 @@
 [Unit]
-Description=Argeo Node %I
+Description=Argeo node %I
 After=network.target
 Wants=postgresql.service
 
 [Service]
 Type=simple
-PIDFile=/var/run/argeo/%i.pid
 ExecStart=/usr/sbin/argeoctl start %I
 ExecReload=/usr/sbin/argeoctl reload %I
-SuccessExitStatus=143
 DynamicUser=true
 StateDirectory=argeo.d/%I
 LogsDirectory=argeo.d/%I
 ConfigurationDirectory=argeo.d/%I
 
+# Workaround to pass locations for systemd with version < 240
+Environment=INSTANCE_DIR=/var/lib/argeo.d/%I CONF_DIR=/etc/argeo.d/%I
+#Environment="INSTANCE_DIR=$STATE_DIRECTORY" "CONF_DIR=$CONFIGURATION_DIRECTORY"
+PassEnvironment=INSTANCE_DIR CONF_DIR
+
 [Install]
 WantedBy=multi-user.target
index 27956e1b67dbc5eb10897777d01a058df77e5cc4..198d5080d23e5485271c7b955eb4662de26375be 100644 (file)
@@ -1,12 +1,7 @@
 [Unit]
-Description=Argeo Node %I
+Description=Argeo user node %I for %u
 
 [Service]
 Type=simple
-PIDFile=/var/run/user/%U/%i.pid
 ExecStart=/usr/sbin/argeoctl start %I
 ExecReload=/usr/sbin/argeoctl reload %I
-SuccessExitStatus=143
-StateDirectory=argeo.d/%I
-LogsDirectory=argeo.d/%I
-ConfigurationDirectory=argeo.d/%I
index 67b08ebcd438fd2a0bee9e057789d6a5d93481c2..c355308140cbae1b677ccbbacda9d54db6477200 100755 (executable)
@@ -3,35 +3,34 @@ APP=argeo
 
 if [ -z "$2" ]; then
 # Default node
+echo Argeo default node
 CONF_DIR=/etc/$APP
 EXEC_DIR=/var/lib/$APP
+
 else
 # Instance
 INSTANCE=$2
-       if [ -z "$STATE_DIRECTORY" ]; then
-       INSTANCE_DIR=$HOME/.local/share/$APP.d/$INSTANCE
-       else
-       # systemd StateDirectory=
-       INSTANCE_DIR=$STATE_DIRECTORY
-       fi
-       if [ -z "$CONFIGURATION_DIRECTORY" ]; then
-       CONF_DIR=$HOME/.config/$APP.d/$INSTANCE
-       else
-       # systemd ConfigurationDirectory=
-       CONF_DIR=$CONFIGURATION_DIRECTORY
-       fi
-       
+echo Argeo instance $INSTANCE
+  if [ -z "$INSTANCE_DIR" ]; then
+  INSTANCE_DIR=$HOME/.local/share/$APP.d/$INSTANCE
+  fi
+  if [ -z "$CONF_DIR" ]; then
+  CONF_DIR=$HOME/.config/$APP.d/$INSTANCE
+  fi  
 EXEC_DIR=$INSTANCE_DIR
-
-       if [ ! -f $CONF_DIR/$APP.ini ]; then
-       cp /etc/$APP/$APP.ini $CONF_DIR
-       fi
-       if [ ! -f $CONF_DIR/log4j.properties ]; then
-       cp /etc/$APP/log4j.properties $CONF_DIR
-       fi
+# Make sure minimal files are available
+  if [ ! -f $CONF_DIR/$APP.ini ]; then
+  cp /etc/$APP/$APP.ini $CONF_DIR
+  fi
+  if [ ! -f $CONF_DIR/log4j.properties ]; then
+  cp /etc/$APP/log4j.properties $CONF_DIR
+  fi
 fi
 
+# Java
+if [ -z "$JVM" ]; then
 JVM=java
+fi
 
 # Directories and files
 
@@ -50,112 +49,52 @@ OSGI_FRAMEWORK=$OSGI_INSTALL_AREA/org.eclipse.osgi.jar
 
 # Overwrite variables
 if [ -f $CONF_DIR/settings.sh ];then
-       . $CONF_DIR/settings.sh
+  . $CONF_DIR/settings.sh
 fi
 
 RETVAL=0
 
+## START ##
 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;
+mkdir -p $CONF_RW
+mkdir -p $DATA_DIR
+
+# Merge config files
+printf "## Equinox configuration - Generated by /usr/sbin/argeoctl ##\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
+# Concatenate additional .ini files
+if [ -d "$CONF_DIRS" ]; then
+for file in `ls -v $CONF_DIRS/*.ini`; do
+  printf "\n##\n## $file\n##\n\n" >> $CONFIG_INI
+  cat $file >> $CONFIG_INI
+done;
+fi
 
-       cd $EXEC_DIR
-       $JVM \
-               -Dlog4j.configuration="file:$CONF_DIR/log4j.properties" \
-               $JAVA_OPTS -jar $OSGI_FRAMEWORK \
-               -Dargeo.osgi.sources=$A2_SOURCES \
-               -configuration "$CONF_RW" \
-               -data "$DATA_DIR"
+cd $EXEC_DIR
+$JVM \
+  -Dlog4j.configuration="file:$CONF_DIR/log4j.properties" \
+  $JAVA_OPTS -jar $OSGI_FRAMEWORK \
+  -Dargeo.osgi.sources=$A2_SOURCES \
+  -configuration "$CONF_RW" \
+  -data "$DATA_DIR"
 }
 
+## RELOAD ##
 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
+echo Not yet implemented
 }
 
 # main
 case "$1" in
-  start)
-        start
-        ;;
-  reload)
-        reload
-        ;;
-  stop)
-        stop
-        ;;
-  status)
-       status
-        ;;
-  *)
-        echo $"Usage: $0 {start|stop|status}"
-        exit 1
+start)
+  start
+  ;;
+reload)
+  reload
+  ;;
+*)
+  echo $"Usage: $0 {start|reload}"
+  exit 1
 esac
\ No newline at end of file