#!/usr/bin/bash

# shellcheck disable=SC1091
. /bin/configure-ironic.sh

# Ramdisk logs
mkdir -p /shared/log/ironic/deploy

# Allows skipping dbsync if it's done by an external job
if [[ "${IRONIC_SKIP_DBSYNC:-false}" != true ]]; then
    run_ironic_dbsync
fi

configure_restart_on_certificate_update "${IRONIC_TLS_SETUP}" ironic "${IRONIC_CERT_FILE}"

configure_ironic_auth

if [[ -d "${BMC_CACERTS_PATH}" ]]; then
    # shellcheck disable=SC2034
    watchmedo shell-command \
        --patterns="*" \
        --ignore-directories \
        --command='cat "${BMC_CACERTS_PATH}"/* > "${BMC_CACERT_FILE}"' \
        "${BMC_CACERTS_PATH}" &
fi

exec /usr/bin/ironic --config-dir "${IRONIC_CONF_DIR}"
