Use mkdir -p while creating prometheus directory

On Re-run, prometheus directory exists and the run fails
with mkdir: cannot create directory ‘/etc/prometheus’: File exists.

Or when we use sg_core plugin with their prothemeus config file,
It also creates prometheus config directory. Then again prometheus
devstack plugin fails with same error.

In order to fix it, use mkdir -p while creating prometheus directory.
It will ignore error if parent exists.

Depends-On: https://review.opendev.org/c/openstack/watcher/+/946230

Change-Id: Ie82346577d836d61c5ca986614e431adbf216d6d
Signed-off-by: Chandan Kumar (raukadah) <raukadah@gmail.com>
This commit is contained in:
Chandan Kumar (raukadah) 2025-04-03 19:15:13 +05:30
parent c9faa98672
commit d8ffce23ff

View File

@ -37,7 +37,8 @@ function install_prometheus {
function configure_prometheus {
# Configure prometheus
sudo mkdir /etc/prometheus
sudo mkdir -p /etc/prometheus
sudo chown $(whoami):$(whoami) /etc/prometheus
# Copy User's prometheus config
@ -50,7 +51,7 @@ function configure_prometheus {
sudo cat /etc/prometheus/$(basename ${PROMETHEUS_CONFIG_FILE})
# Create data directory
sudo mkdir ${PROMETHEUS_DATA_DIRECTORY}
sudo mkdir -p ${PROMETHEUS_DATA_DIRECTORY}
sudo chown $(whoami):$(whoami) ${PROMETHEUS_DATA_DIRECTORY}
}