cScm Configuration Daemon

cScm – is a tool to convert SCM configuration files into binary format and store its in shared memory for reading by cSvn-ui and cGit-ui CGI scripts

12 Commits   0 Branches   1 Tag
Index: rc.cscmd.in
===================================================================
--- rc.cscmd.in	(nonexistent)
+++ rc.cscmd.in	(revision 5)
@@ -0,0 +1,96 @@
+#!/bin/sh
+#
+# /etc/rc.d/rc.@CSCM_PROGRAM@d - @CSCM_PROGRAM_NAME@ daemon control script.
+#
+
+BIN=@sbindir@/@PROGRAM_DAEMON@
+CONF=@CSCM_CONFIG@
+BCF=@CSCM_HOME_PATH@/@CSCM_PROGRAM@/@CSCM_PROGRAM@.bcf
+PID=@CSCM_PID_DIR@/@CSCM_PROGRAM@d.pid
+LOG=@CSCM_LOG_DIR@/@CSCM_PROGRAM@d.log
+
+INOTIFY=--inotify
+
+cscmd_start() {
+  # Sanity checks.
+  if [ ! -r $CONF ]; then
+    echo "$CONF does not appear to exist. Abort."
+    exit 1
+  fi
+
+  if [ -s $PID ]; then
+    echo "@CSCM_PROGRAM_NAME@ daemon appears to already be running?"
+    exit 1
+  fi
+
+  echo "Starting @CSCM_PROGRAM_NAME@ server daemon..."
+  if [ -x $BIN ]; then
+    $BIN --daemonize $INOTIFY --scm=@CSCM_NAME@ --pid=$PID --log=$LOG --bcf=$BCF --config=$CONF
+  fi
+}
+
+cscmd_test_conf() {
+  echo "Checking configuration for correct syntax and then"
+  echo "trying to open files referenced in configuration..."
+  echo ""
+  if [ -s $PID ] ; then
+    echo "@PROGRAM_DAEMON@: $CONF: Config file is correct."
+  else
+    $BIN --test --scm=@CSCM_NAME@ --pid=$PID --log=$LOG --bcf=$BCF --config=$CONF
+  fi
+}
+
+cscmd_status() {
+  if [ -s $PID ] ; then
+    echo "@CSCM_PROGRAM_NAME@ daemon is running as PID: $(cat $PID)"
+  else
+    echo "@CSCM_PROGRAM_NAME@ daemon is stopped."
+  fi
+}
+
+cscmd_stop() {
+  echo "Shutdown @CSCM_PROGRAM_NAME@ daemon gracefully..."
+  if [ -s $PID ] ; then
+    kill -TERM $(cat $PID)
+  else
+    echo "@CSCM_PROGRAM_NAME@ daemon appears to already be stopped."
+  fi
+}
+
+cscmd_reload() {
+  echo "Reloading @CSCM_PROGRAM_NAME@ daemon configuration..."
+  if [ -s $PID ] ; then
+    kill -HUP $(cat $PID)
+  else
+    echo "@CSCM_PROGRAM_NAME@ daemon is not running."
+  fi
+}
+
+cscmd_restart() {
+  cscmd_stop
+  sleep 3
+  cscmd_start
+}
+
+case "$1" in
+  check)
+    cscmd_test_conf
+    ;;
+  reload)
+    cscmd_reload
+    ;;
+  restart)
+    cscmd_restart
+    ;;
+  start)
+    cscmd_start
+    ;;
+  stop)
+    cscmd_stop
+    ;;
+  status)
+    cscmd_status
+    ;;
+  *)
+  echo "usage: `basename $0` {check|reload|restart|start|stop|status}"
+esac