Commit cd582532 authored by Kostas Papadimitriou's avatar Kostas Papadimitriou
Browse files

Updated init.d script for snf-dispatcher

parent 37849ab3
......@@ -4,15 +4,14 @@
# init.d script
#
VERBOSE=yes
# Run as a daemon? true/false
SNF_DSPTCH_ENABLE=false
SNF_DSPTCH_ENABLE=true
# 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
......
#! /bin/sh
#!/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
# 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
# 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
DAEMON=/usr/bin/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
SNF_DSPTCH_RUNDIR=/var/run/synnefo
SNF_DSPTCH_PID_FILE=$SNF_DSPTCH_RUNDIR/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_DEFAULTS_FILE
SNF_DSPTCH_OPTS=$SNF_DSPTCH_OPTS" -p $SNF_DSPTCH_PID_FILE"
case "x$SNF_DSPTCH_ENABLE" in
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
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
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)
# Ensure the directory containing the pidfile exists
# and has the right permissions
mkdir -p $SNF_DSPTCH_RUNDIR
chown $SNF_USER $SNF_DSPTCH_RUNDIR
chmod 0755 $SNF_DSPTCH_RUNDIR
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_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
dispatcher_start
else
[ "$VERBOSE" != no ] && log_warning_msg "snf-dispatcher daemon not enabled in $SNF_DSPTCH_DEFAULTS_FILE, not starting..."
fi
;;
stop)
......@@ -90,19 +89,17 @@ case "$1" in
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
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
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
rm -f $SNF_DSPTCH_PID_FILE
fi
dispatcher_start
else
[ "$VERBOSE" != no ] && log_warning_msg "dispatcher daemon not enabled in $SNF_DSPTCH_DEFAULTS_FILE, not starting..."
fi
;;
......@@ -116,3 +113,4 @@ case "$1" in
esac
exit 0
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment