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

set -e

# set up prometheus for multiprocess configuration
export prometheus_multiproc_dir=/tmp/prometheus
# ensure the dir exists and it's empty
rm -rf "$prometheus_multiproc_dir"
mkdir -p "$prometheus_multiproc_dir"

# Render the supervisord.conf based on the current mode.
"$SNAP/snap/command-chain/snapcraft-runner" "$SNAP/command-maas.wrapper" config --render

# Run the supervisor for the snap.
exec "$SNAP/bin/supervisord" -d "$SNAP_DATA/supervisord" -c "$SNAP_DATA/supervisord/supervisord.conf" -n > "$SNAP_COMMON/log/supervisor.log" 2>&1
