#!/bin/bash
set -eux

TEMPLATE_ROOT=$(dirname $0)/../os-apply-config

get_additional_config(){
    if [ -e ${TEMPLATE_ROOT}/etc/nova/nova-${1}.conf ]; then
        echo "--config-file /etc/nova/nova.conf --config-file /etc/nova/nova-${1}.conf"
    fi
}

NOVA_COMPONENTS="api cert scheduler consoleauth conductor"

for component in $NOVA_COMPONENTS; do
    os-svc-daemon -i "${NOVA_VENV_DIR}" nova-${component} nova nova-${component} "--config-dir /etc/nova $(get_additional_config ${component})"
done

ln -s $NOVA_VENV_DIR/bin/nova-manage /usr/local/bin/nova-manage
