#!/bin/bash
export RESTART_CONTAINER_CERTIFICATE_UPDATED=${RESTART_CONTAINER_CERTIFICATE_UPDATED:-"false"}
export IRONIC_CACERT_FILE=${IRONIC_CACERT_FILE:-"/opt/metal3/certs/ca/tls.crt"}

if [[ "${RESTART_CONTAINER_CERTIFICATE_UPDATED}" == "true" ]]; then
     watchmedo shell-command \
            --patterns="$(basename "${IRONIC_CACERT_FILE}")" \
            --ignore-directories \
            --command='if [[ "${watch_event_type}" == "deleted" ]]; then pkill -TERM baremetal-opera; fi' \
            "$(dirname "${IRONIC_CACERT_FILE}")" &
fi

exec /usr/bin/baremetal-operator $@