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

Merge branch 'packaging-kpap'

parents a2a0c8cb cd582532
......@@ -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
......@@ -199,7 +199,7 @@ setup(
entry_points = {
'console_scripts': [
'snf-dispatcher = synnefo.logic.dispatcher:scriptmain',
'snf-dispatcher = synnefo.logic.dispatcher:main',
'snf-burnin = synnefo.tools.burnin:main',
'snf-admin = synnefo.tools.admin:main',
'snf-cloud = synnefo.tools.cloud:main',
......
......@@ -229,15 +229,15 @@ def child(cmdline):
def parse_arguments(args):
from optparse import OptionParser
default_pid_file = os.path.join("var","run","synnefo","dispatcher.pid")
parser = OptionParser()
parser.add_option("-d", "--debug", action="store_true", default=False,
dest="debug", help="Enable debug mode")
parser.add_option("-w", "--workers", default=2, dest="workers",
help="Number of workers to spawn", type="int")
parser.add_option("-p", '--pid-file', dest="pid_file",
default=os.path.join(os.getcwd(), "dispatcher.pid"),
help="Save PID to file (default:%s)" %
os.path.join(os.getcwd(), "dispatcher.pid"))
parser.add_option("-p", "--pid-file", dest="pid_file",
default=default_pid_file,
help="Save PID to file (default: %s)" % default_pid_file)
parser.add_option("--purge-queues", action="store_true",
default=False, dest="purge_queues",
help="Remove all declared queues (DANGEROUS!)")
......@@ -416,7 +416,10 @@ def daemon_mode(opts):
def main():
dictConfig(settings.DISPATCHER_LOGGING)
global log
(opts, args) = parse_arguments(sys.argv[1:])
# Init the global variables containing the queues
......@@ -461,11 +464,7 @@ def main():
raise
def scriptmain():
dictConfig(settings.DISPATCHER_LOGGING)
sys.exit(main())
if __name__ == "__main__":
scriptmain()
sys.exit(main())
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
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