Added bdbserver script to be added to /etc/init.d jenkins-baltrad-db-423
authorAnders Henja <anders@henjab.se>
Thu, 30 Aug 2018 20:47:00 +0000 (22:47 +0200)
committerAnders Henja <anders@henjab.se>
Thu, 30 Aug 2018 20:47:00 +0000 (22:47 +0200)
server/etc/bdbserver [new file with mode: 0755]

diff --git a/server/etc/bdbserver b/server/etc/bdbserver
new file mode 100755 (executable)
index 0000000..69d1b72
--- /dev/null
@@ -0,0 +1,123 @@
+#!/bin/sh
+#
+# /etc/init.d/bdbserver - used to start and stop the baltrad-bdb-server
+#
+### BEGIN INIT INFO
+# Provides:          bdbserver
+# Required-Start:    $local_fs $remote_fs $network
+# Required-Stop:     $local_fs $remote_fs $network
+# Should-Start:      $named
+# Should-Stop:       $named
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Start baltrad db server.
+# Description:       Start the baltrad db server.
+### END INIT INFO
+
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+NAME=bdbserver
+DESC="Baltrad db server"
+DEFAULT=/etc/default/$NAME
+BALTRAD_DB_PID_DIR=/var/run/baltrad
+BALTRAD_DB_LOG_DIR=/var/log/baltrad
+BDBPID=${BALTRAD_DB_PID_DIR}/baltrad-bdb-server.pid
+BDBLOG=${BALTRAD_DB_LOG_DIR}/baltrad-bdb-server.log
+
+if [ `id -u` -ne 0 ]; then
+       echo "You need root privileges to run this script"
+       exit 1
+fi
+
+# Run as user
+BALTRAD_USER=tomcat7
+BALTRAD_GROUP=tomcat7
+
+# Checks status of the bdb pid
+get_bdb_pid() {
+  local  __resultvar=$1
+  local  result=''
+
+  if [ -f "$BDBPID" ]; then
+    result=`cat $BDBPID`
+  fi
+
+  eval $__resultvar="'$result'"
+}
+
+# Checks if the process is running
+check_bdb_status() {
+  get_bdb_pid pid
+  if [ $pid ]; then
+    ps -p $pid > /dev/null
+    return $?
+  else
+    return 1
+  fi
+}
+
+if [ ! -d "$BALTRAD_DB_PID_DIR" ]; then
+  echo "Creating dirname $BALTRAD_DB_PID_DIR"
+  mkdir "$BALTRAD_DB_PID_DIR"
+  if [ $? -ne 0 ]; then
+    echo "Failed to create pid file directory, defaulting to /tmp/baltrad-bdb-server.pid"
+    BDBPID=/tmp/baltrad-bdb-server.pid
+  else
+    chown $BALTRAD_USER:$BALTRAD_GROUP "$BALTRAD_DB_PID_DIR"
+  fi
+fi
+
+if [ ! -d "$BALTRAD_DB_LOG_DIR" ]; then
+  echo "Creating dirname $BALTRAD_DB_LOG_DIR"
+  mkdir "$BALTRAD_DB_LOG_DIR"
+  if [ $? -ne 0 ]; then
+    echo "Failed to create log directory, defaulting to /tmp/baltrad-bdb-server.log"
+    BDBLOG=/tmp/baltrad-bdb-server.log
+  else
+    chown $BALTRAD_USER:$BALTRAD_GROUP "$BALTRAD_DB_LOG_DIR"
+  fi
+fi
+
+case "$1" in
+  start)
+    echo -n "Starting BDB..."
+    check_bdb_status
+    if [ $? -eq 0 ]; then
+      echo "already running"
+    else
+      su $BALTRAD_USER -s /bin/bash -c "baltrad-bdb-server --pidfile=$BDBPID --conf=/etc/baltrad/bltnode.properties --logfile=$BDBLOG"
+      if [ $? -ne 0 ]; then
+        echo "failed."
+      else
+        echo "done."
+      fi
+    fi
+    ;;
+  stop)
+    echo -n "Stopping BDB..."
+    get_bdb_pid pid
+    if [ $pid ]; then
+      kill $pid 2&> /dev/null
+      echo "done"
+    else
+      echo "not running"
+    fi
+    ;;    
+  status)
+    check_bdb_status
+    if [ $? -eq 0 ]; then
+      echo "Running"
+    else
+      echo "Stopped"
+    fi
+    ;;
+  restart)
+    $0 stop
+    sleep 1
+    $0 start
+    ;;
+  *)
+    echo "Usage: $0 {start|stop|restart|status}"
+    ;;
+esac
+
+exit 0