commit a1ac271fa3424b852c88e4d908fb7981537f7a65
Author: Kostas Papadimitriou <kpap@grnet.gr>
Date:   Mon Jan 16 16:45:44 2012 +0200

    Added init.d file for snf-dispatcher

diff --git a/snf-app/conf/default/snf-dispatcher b/snf-app/conf/default/snf-dispatcher
new file mode 100644
index 0000000..c3baf3a
--- /dev/null
+++ b/snf-app/conf/default/snf-dispatcher
@@ -0,0 +1,19 @@
+#!/bin/sh
+#
+# This file is a shell script to be sourced by the appropriate 
+# init.d script
+#
+
+# Run as a daemon? true/false
+SNF_DSPTCH_ENABLE=false
+
+# User to run the dispatcher as
+SNF_USER="www-data"
+
+# Daemon needs to be run from a specific directory atm (FIX)
+SNF_DAEMON_DIR="/srv/okeanos"
+
+# How many workers, default 2
+WORKERS=2
+
+SNF_DPTCH_OPTS="--workers=2"
diff --git a/snf-app/conf/init.d/snf-dispatcher b/snf-app/conf/init.d/snf-dispatcher
new file mode 100755
index 0000000..1356a61
--- /dev/null
+++ b/snf-app/conf/init.d/snf-dispatcher
@@ -0,0 +1,118 @@
+#! /bin/sh
+
+### BEGIN INIT INFO
+# Provides:          snf-dispatcher
+# Required-Start:    $remote_fs $syslog
+# Required-Stop:     $remote_fs $syslog
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Synnefo dispatcher daemon
+# Description:       Dispatcher is a daemon for the synnefo middleware logic layer
+### END INIT INFO
+
+set -e
+
+# /etc/init.d/snf-dispatcher: start and stop the dispatcher daemon
+
+DAEMON=snf-dispatcher
+SNF_DSPTCH_OPTS=''
+SNF_DSPTCH_DEFAULTS_FILE=/etc/default/snf-dispatcher
+SNF_DSPTCH_CONFIG_FILE=/etc/snf-dispatcher.conf
+SNF_DSPTCH_PID_FILE=/var/run/synnefo/snf_dispatcher.pid
+
+test -x $DAEMON || exit 0
+
+. /lib/lsb/init-functions
+
+if [ -s $SNF_DSPTCH_DEFAULTS_FILE ]; then
+    . $SNF_DSPTCH_DEFAULTS_FILE
+	SNF_DSPTCH_OPTS=$SNF_DSPTCH_OPTS" -p $SNF_DSPTCH_PID_FILE"
+    case "x$SNF_DSPTCH_ENABLE" in
+	xtrue|xfalse)	;;
+	*)		log_failure_msg "Value of SNF_DSPTCH_ENABLE in $SNF_DSPTCH_DEFAULTS_FILE must be either 'true' or 'false';"
+			log_failure_msg "not starting dispatcher daemon."
+			exit 1
+			;;
+    esac
+fi
+
+export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
+
+dispatcher_start() {
+    if [ ! -s "$SNF_DSPTCH_CONFIG_FILE" ]; then
+        log_failure_msg "missing or empty config file $SNF_DSPTCH_CONFIG_FILE"
+        log_end_msg 1
+        exit 0
+    fi
+	if start-stop-daemon --start --chuid $SNF_USER --exec $DAEMON -- $SNF_DSPTCH_OPTS
+    then
+        rc=0
+        sleep 1
+        if ! kill -0 $(cat $SNF_DSPTCH_PID_FILE) >/dev/null 2>&1; then
+            log_failure_msg "snf-dispatcher daemon failed to start"
+            rc=1
+        fi
+    else
+        rc=1
+    fi
+    if [ $rc -eq 0 ]; then
+        log_end_msg 0
+    else
+        log_end_msg 1
+        rm -f $SNF_DSPTCH_PID_FILE
+    fi
+} # dispatcher_start
+
+
+case "$1" in
+  start)
+	if "$SNF_DSPTCH_ENABLE"; then
+	    log_daemon_msg "Starting snf-dispatcher daemon" "snf-dispatcher"
+	    if [ -s $SNF_DSPTCH_PID_FILE ] && kill -0 $(cat $SNF_DSPTCH_PID_FILE) >/dev/null 2>&1; then
+		log_progress_msg "apparently already running"
+		log_end_msg 0
+		exit 0
+	    fi
+            dispatcher_start
+        else
+            if [ -s "$SNF_DSPTCH_CONFIG_FILE" ]; then
+                [ "$VERBOSE" != no ] && log_warning_msg "snf-dispatcher daemon not enabled in $SNF_DSPTCH_DEFAULTS_FILE, not starting..."
+            fi
+	fi
+	;;
+  stop)
+	log_daemon_msg "Stopping snf-dispatcher daemon" "snf-dispatcher"
+	start-stop-daemon --stop --quiet --oknodo --pidfile $SNF_DSPTCH_PID_FILE
+	log_end_msg $?
+	rm -f $SNF_DSPTCH_PID_FILE
+	;;
+
+  restart)
+	set +e
+	if $SNF_DSPTCH_ENABLE; then
+	    log_daemon_msg "Restarting dispatcher daemon" "dispatcher"
+	    if [ -s $SNF_DSPTCH_PID_FILE ] && kill -0 $(cat $SNF_DSPTCH_PID_FILE) >/dev/null 2>&1; then
+		start-stop-daemon --stop --quiet --oknodo --pidfile $SNF_DSPTCH_PID_FILE || true
+		sleep 1
+	    else
+		log_warning_msg "dispatcher daemon not running, attempting to start."
+	    	rm -f $SNF_DSPTCH_PID_FILE
+	    fi
+            dispatcher_start
+        else
+            if [ -s "$SNF_DSPTCH_CONFIG_FILE" ]; then
+                [ "$VERBOSE" != no ] && log_warning_msg "dispatcher daemon not enabled in $SNF_DSPTCH_DEFAULTS_FILE, not starting..."
+            fi
+	fi
+	;;
+
+  status)
+	status_of_proc -p $SNF_DSPTCH_PID_FILE "$DAEMON" dispatcher
+	exit $?	# notreached due to set -e
+	;;
+  *)
+	echo "Usage: /etc/init.d/snf-dispatcher {start|stop|restart|status}"
+	exit 1
+esac
+
+exit 0
