#!/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"

# Exec the Provisioning Server.
script="$(readlink -f bin/twistd.pserv)"
config="$(readlink -f etc/pserv.yaml)"

# Set a fixed cluster UUID.  This is identical for all cluster services
# running in the demo setup: they're all the same cluster.
export CLUSTER_UUID="adfd3977-f251-4f2c-8d61-745dbd690bfc"

exec $(command -v authbind && echo --deep) \
    "${script}" --nodaemon --pidfile="" maas-pserv --config-file "${config}"
