#!/usr/bin/env bash
# Copyright 2012 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

# Exit immediately if a command exits with a non-zero status.
set -o errexit
# Treat unset variables as an error when substituting.
set -o nounset

# Move to the project root.
cd "$(dirname "$0")/../.."

# Start logging, if requested. Not using multilog here right now
# because there are race issues when restarting.
[ -z "${logdir:-}" ] || exec &>> "${logdir}/current"

export PYTHONPATH=etc/:src/
export DJANGO_SETTINGS_MODULE=maas.demo
script="$(readlink -f bin/celeryd.region)"
# XXX GavinPanella 2013-01-02, bug=1040529: celeryd does not shutdown
# correctly when signalled: processes are often left behind. However,
# pgrphack works around this, ensuring a complete shutdown.
exec pgrphack "${script}" \
    --loglevel INFO --beat --queues celery,master \
    --schedule=run/celerybeat-region-schedule \
    --config=democeleryconfig
