From a5a469c102c091255ffacd284be123da9a98a539 Mon Sep 17 00:00:00 2001
From: Swapnil Kulkarni <me@coolsvap.net>
Date: Fri, 3 Jul 2015 05:26:39 +0000
Subject: [PATCH] Add config-internal/config-external for cinder

Partially Implements: Blueprint standard-start

Change-Id: I9fa5cc8f6f57b46f8af165778388435b91c28447
---
 .../binary/cinder-app/cinder-api/Dockerfile   |  1 +
 .../cinder-app/cinder-api/config-external.sh  |  1 +
 .../cinder-app/cinder-api/config-internal.sh  |  1 +
 .../cinder-app/cinder-backup/Dockerfile       |  1 +
 .../cinder-backup/config-external.sh          |  1 +
 .../cinder-backup/config-internal.sh          |  1 +
 .../cinder-app/cinder-scheduler/Dockerfile    |  1 +
 .../cinder-scheduler/config-external.sh       |  1 +
 .../cinder-scheduler/config-internal.sh       |  1 +
 .../cinder-app/cinder-volume/Dockerfile       |  1 +
 .../cinder-volume/config-external.sh          |  1 +
 .../cinder-volume/config-internal.sh          |  1 +
 .../cinder-app/cinder-api/config-external.sh  | 10 +++
 .../cinder-app/cinder-api/config-internal.sh  | 71 +++++++++++++++
 docker/common/cinder-app/cinder-api/start.sh  | 79 +++--------------
 .../cinder-backup/config-external.sh          |  9 ++
 .../cinder-backup/config-internal.sh          | 45 ++++++++++
 .../common/cinder-app/cinder-backup/start.sh  | 47 ++--------
 .../cinder-scheduler/config-external.sh       | 10 +++
 .../cinder-scheduler/config-internal.sh       | 32 +++++++
 .../cinder-app/cinder-scheduler/start.sh      | 34 ++------
 .../cinder-volume/config-external.sh          | 10 +++
 .../cinder-volume/config-internal.sh          | 84 ++++++++++++++++++
 .../common/cinder-app/cinder-volume/start.sh  | 86 ++-----------------
 24 files changed, 321 insertions(+), 208 deletions(-)
 create mode 120000 docker/centos/binary/cinder-app/cinder-api/config-external.sh
 create mode 120000 docker/centos/binary/cinder-app/cinder-api/config-internal.sh
 create mode 120000 docker/centos/binary/cinder-app/cinder-backup/config-external.sh
 create mode 120000 docker/centos/binary/cinder-app/cinder-backup/config-internal.sh
 create mode 120000 docker/centos/binary/cinder-app/cinder-scheduler/config-external.sh
 create mode 120000 docker/centos/binary/cinder-app/cinder-scheduler/config-internal.sh
 create mode 120000 docker/centos/binary/cinder-app/cinder-volume/config-external.sh
 create mode 120000 docker/centos/binary/cinder-app/cinder-volume/config-internal.sh
 create mode 100644 docker/common/cinder-app/cinder-api/config-external.sh
 create mode 100644 docker/common/cinder-app/cinder-api/config-internal.sh
 create mode 100644 docker/common/cinder-app/cinder-backup/config-external.sh
 create mode 100644 docker/common/cinder-app/cinder-backup/config-internal.sh
 create mode 100644 docker/common/cinder-app/cinder-scheduler/config-external.sh
 create mode 100644 docker/common/cinder-app/cinder-scheduler/config-internal.sh
 create mode 100644 docker/common/cinder-app/cinder-volume/config-external.sh
 create mode 100644 docker/common/cinder-app/cinder-volume/config-internal.sh

diff --git a/docker/centos/binary/cinder-app/cinder-api/Dockerfile b/docker/centos/binary/cinder-app/cinder-api/Dockerfile
index 3d3e3ae8f6..c96caaeccb 100644
--- a/docker/centos/binary/cinder-app/cinder-api/Dockerfile
+++ b/docker/centos/binary/cinder-app/cinder-api/Dockerfile
@@ -2,6 +2,7 @@ FROM %%KOLLA_NAMESPACE%%/%%KOLLA_PREFIX%%cinder-base:%%KOLLA_TAG%%
 MAINTAINER Kolla Project (https://launchpad.net/kolla)
 
 RUN yum install -y python-keystone && yum clean all
+COPY config-internal.sh config-external.sh /opt/kolla/
 COPY ./start.sh ./check.sh /
 
 CMD ["/start.sh"]
diff --git a/docker/centos/binary/cinder-app/cinder-api/config-external.sh b/docker/centos/binary/cinder-app/cinder-api/config-external.sh
new file mode 120000
index 0000000000..5b577f2903
--- /dev/null
+++ b/docker/centos/binary/cinder-app/cinder-api/config-external.sh
@@ -0,0 +1 @@
+../../../../common/cinder-app/cinder-api/config-external.sh
\ No newline at end of file
diff --git a/docker/centos/binary/cinder-app/cinder-api/config-internal.sh b/docker/centos/binary/cinder-app/cinder-api/config-internal.sh
new file mode 120000
index 0000000000..d929c89b20
--- /dev/null
+++ b/docker/centos/binary/cinder-app/cinder-api/config-internal.sh
@@ -0,0 +1 @@
+../../../../common/cinder-app/cinder-api/config-internal.sh
\ No newline at end of file
diff --git a/docker/centos/binary/cinder-app/cinder-backup/Dockerfile b/docker/centos/binary/cinder-app/cinder-backup/Dockerfile
index fb44155b30..43994f1238 100644
--- a/docker/centos/binary/cinder-app/cinder-backup/Dockerfile
+++ b/docker/centos/binary/cinder-app/cinder-backup/Dockerfile
@@ -2,5 +2,6 @@ FROM %%KOLLA_NAMESPACE%%/%%KOLLA_PREFIX%%cinder-base:%%KOLLA_TAG%%
 MAINTAINER Kolla Project (https://launchpad.net/kolla)
 
 COPY ./start.sh /start.sh
+COPY config-internal.sh config-external.sh /opt/kolla/
 
 CMD ["/start.sh"]
diff --git a/docker/centos/binary/cinder-app/cinder-backup/config-external.sh b/docker/centos/binary/cinder-app/cinder-backup/config-external.sh
new file mode 120000
index 0000000000..c80c21a204
--- /dev/null
+++ b/docker/centos/binary/cinder-app/cinder-backup/config-external.sh
@@ -0,0 +1 @@
+../../../../common/cinder-app/cinder-backup/config-external.sh
\ No newline at end of file
diff --git a/docker/centos/binary/cinder-app/cinder-backup/config-internal.sh b/docker/centos/binary/cinder-app/cinder-backup/config-internal.sh
new file mode 120000
index 0000000000..5f135c63bb
--- /dev/null
+++ b/docker/centos/binary/cinder-app/cinder-backup/config-internal.sh
@@ -0,0 +1 @@
+../../../../common/cinder-app/cinder-backup/config-internal.sh
\ No newline at end of file
diff --git a/docker/centos/binary/cinder-app/cinder-scheduler/Dockerfile b/docker/centos/binary/cinder-app/cinder-scheduler/Dockerfile
index 344dc142f5..1014e3dcef 100644
--- a/docker/centos/binary/cinder-app/cinder-scheduler/Dockerfile
+++ b/docker/centos/binary/cinder-app/cinder-scheduler/Dockerfile
@@ -2,5 +2,6 @@ FROM %%KOLLA_NAMESPACE%%/%%KOLLA_PREFIX%%cinder-base:%%KOLLA_TAG%%
 MAINTAINER Kolla Project (https://launchpad.net/kolla)
 
 ADD ./start.sh /start.sh
+COPY config-internal.sh config-external.sh /opt/kolla/
 
 CMD ["/start.sh"]
diff --git a/docker/centos/binary/cinder-app/cinder-scheduler/config-external.sh b/docker/centos/binary/cinder-app/cinder-scheduler/config-external.sh
new file mode 120000
index 0000000000..9762490029
--- /dev/null
+++ b/docker/centos/binary/cinder-app/cinder-scheduler/config-external.sh
@@ -0,0 +1 @@
+../../../../common/cinder-app/cinder-scheduler/config-external.sh
\ No newline at end of file
diff --git a/docker/centos/binary/cinder-app/cinder-scheduler/config-internal.sh b/docker/centos/binary/cinder-app/cinder-scheduler/config-internal.sh
new file mode 120000
index 0000000000..f3792cd9c4
--- /dev/null
+++ b/docker/centos/binary/cinder-app/cinder-scheduler/config-internal.sh
@@ -0,0 +1 @@
+../../../../common/cinder-app/cinder-scheduler/config-internal.sh
\ No newline at end of file
diff --git a/docker/centos/binary/cinder-app/cinder-volume/Dockerfile b/docker/centos/binary/cinder-app/cinder-volume/Dockerfile
index d82fed03c3..0daf6d29e4 100644
--- a/docker/centos/binary/cinder-app/cinder-volume/Dockerfile
+++ b/docker/centos/binary/cinder-app/cinder-volume/Dockerfile
@@ -11,6 +11,7 @@ RUN yum install -y lvm2 scsi-target-utils && yum clean all
 
 # Add start scripts
 COPY start.sh /start.sh
+COPY config-internal.sh config-external.sh /opt/kolla/
 COPY volume-group-create.sh /opt/kolla/volume-group-create.sh
 
 # Start supervisor
diff --git a/docker/centos/binary/cinder-app/cinder-volume/config-external.sh b/docker/centos/binary/cinder-app/cinder-volume/config-external.sh
new file mode 120000
index 0000000000..1f6476f2eb
--- /dev/null
+++ b/docker/centos/binary/cinder-app/cinder-volume/config-external.sh
@@ -0,0 +1 @@
+../../../../common/cinder-app/cinder-volume/config-external.sh
\ No newline at end of file
diff --git a/docker/centos/binary/cinder-app/cinder-volume/config-internal.sh b/docker/centos/binary/cinder-app/cinder-volume/config-internal.sh
new file mode 120000
index 0000000000..4739be2fc5
--- /dev/null
+++ b/docker/centos/binary/cinder-app/cinder-volume/config-internal.sh
@@ -0,0 +1 @@
+../../../../common/cinder-app/cinder-volume/config-internal.sh
\ No newline at end of file
diff --git a/docker/common/cinder-app/cinder-api/config-external.sh b/docker/common/cinder-app/cinder-api/config-external.sh
new file mode 100644
index 0000000000..5f57ab939a
--- /dev/null
+++ b/docker/common/cinder-app/cinder-api/config-external.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+SOURCE="/opt/kolla/cinder/cinder.conf"
+TARGET="/etc/cinder/cinder.conf"
+OWNER="cinder"
+
+if [[ -f "$SOURCE" ]]; then
+    cp $SOURCE $TARGET
+    chown ${OWNER}: $TARGET
+    chmod 0644 $TARGET
+fi
diff --git a/docker/common/cinder-app/cinder-api/config-internal.sh b/docker/common/cinder-app/cinder-api/config-internal.sh
new file mode 100644
index 0000000000..832d4f78a1
--- /dev/null
+++ b/docker/common/cinder-app/cinder-api/config-internal.sh
@@ -0,0 +1,71 @@
+#!/bin/bash
+set -e
+
+. /opt/kolla/kolla-common.sh
+. /opt/kolla/config-cinder.sh
+
+check_required_vars KEYSTONE_ADMIN_TOKEN KEYSTONE_ADMIN_SERVICE_HOST \
+                    ADMIN_TENANT_NAME PUBLIC_IP CINDER_API_SERVICE_HOST \
+                    KEYSTONE_AUTH_PROTOCOL KEYSTONE_ADMIN_SERVICE_PORT \
+                    CINDER_KEYSTONE_USER CINDER_KEYSTONE_PASSWORD \
+                    CINDER_API_SERVICE_LISTEN CINDER_API_SERVICE_PORT
+
+fail_unless_os_service_running keystone
+
+cfg=/etc/cinder/cinder.conf
+
+# Set the auth credentials
+export SERVICE_TOKEN="${KEYSTONE_ADMIN_TOKEN}"
+export SERVICE_ENDPOINT="${KEYSTONE_AUTH_PROTOCOL}://${KEYSTONE_ADMIN_SERVICE_HOST}:${KEYSTONE_ADMIN_SERVICE_PORT}/v2.0"
+
+# Create Keystone User
+crux user-create --update \
+    -n "${CINDER_KEYSTONE_USER}" \
+    -p "${CINDER_KEYSTONE_PASSWORD}" \
+    -t "${ADMIN_TENANT_NAME}" \
+    -r admin
+
+# Configure Keystone
+crux endpoint-create --remove-all \
+    -n cinder \
+    -t volume \
+    -P "http://${CINDER_API_SERVICE_HOST}:${CINDER_API_SERVICE_PORT}/v2/\$(tenant_id)s" \
+    -A "http://${CINDER_API_SERVICE_HOST}:${CINDER_API_SERVICE_PORT}/v2/\$(tenant_id)s" \
+    -I "http://${CINDER_API_SERVICE_HOST}:${CINDER_API_SERVICE_PORT}/v2/\$(tenant_id)s"
+
+crux endpoint-create --remove-all \
+    -n cinderv2 \
+    -t volumev2 \
+    -P "http://${CINDER_API_SERVICE_HOST}:${CINDER_API_SERVICE_PORT}/v2/\$(tenant_id)s" \
+    -A "http://${CINDER_API_SERVICE_HOST}:${CINDER_API_SERVICE_PORT}/v2/\$(tenant_id)s" \
+    -I "http://${CINDER_API_SERVICE_HOST}:${CINDER_API_SERVICE_PORT}/v2/\$(tenant_id)s"
+
+# Logging
+crudini --set $cfg \
+        DEFAULT \
+        log_file \
+        "${CINDER_API_LOG_FILE}"
+
+# API Configuration
+crudini --set $cfg \
+        DEFAULT \
+        osapi_volume_listen \
+        "${CINDER_API_SERVICE_LISTEN}"
+
+crudini --set $cfg \
+        DEFAULT \
+        osapi_volume_listen_port \
+        "${CINDER_API_SERVICE_PORT}"
+
+crudini --set $cfg \
+        DEFAULT \
+        enable_v1_api \
+        "false"
+
+crudini --set $cfg \
+        DEFAULT \
+        enable_v2_api \
+        "true"
+
+echo "Starting cinder-api"
+exec /usr/bin/cinder-api --config-file $cfg
diff --git a/docker/common/cinder-app/cinder-api/start.sh b/docker/common/cinder-app/cinder-api/start.sh
index cbf0159e5e..4385d06311 100755
--- a/docker/common/cinder-app/cinder-api/start.sh
+++ b/docker/common/cinder-app/cinder-api/start.sh
@@ -1,72 +1,21 @@
 #!/bin/bash
 
-set -e
+set -o errexit
 
-. /opt/kolla/kolla-common.sh
-. /opt/kolla/config-cinder.sh
+CMD="/usr/bin/cinder-api"
+ARGS=""
 
-check_required_vars KEYSTONE_ADMIN_TOKEN KEYSTONE_ADMIN_SERVICE_HOST \
-                    ADMIN_TENANT_NAME PUBLIC_IP CINDER_API_SERVICE_HOST \
-                    KEYSTONE_AUTH_PROTOCOL KEYSTONE_ADMIN_SERVICE_PORT \
-                    CINDER_KEYSTONE_USER CINDER_KEYSTONE_PASSWORD \
-                    CINDER_API_SERVICE_LISTEN CINDER_API_SERVICE_PORT
+# Loading common functions.
+source /opt/kolla/kolla-common.sh
 
-fail_unless_os_service_running keystone
+# Config-internal script exec out of this function, it does not return here.
+set_configs
 
-cfg=/etc/cinder/cinder.conf
+# Bootstrap and exit if KOLLA_BOOTSTRAP variable is set. This catches all cases
+# of the KOLLA_BOOTSTRAP variable being set, including empty.
+if [[ "${!KOLLA_BOOTSTRAP[@]}" ]]; then
+    su -s /bin/sh -c "cinder-manage db_sync" cinder
+    exit 0
+fi
 
-# Set the auth credentials
-export SERVICE_TOKEN="${KEYSTONE_ADMIN_TOKEN}"
-export SERVICE_ENDPOINT="${KEYSTONE_AUTH_PROTOCOL}://${KEYSTONE_ADMIN_SERVICE_HOST}:${KEYSTONE_ADMIN_SERVICE_PORT}/v2.0"
-
-# Create Keystone User
-crux user-create --update \
-    -n "${CINDER_KEYSTONE_USER}" \
-    -p "${CINDER_KEYSTONE_PASSWORD}" \
-    -t "${ADMIN_TENANT_NAME}" \
-    -r admin
-
-# Configure Keystone
-crux endpoint-create --remove-all \
-    -n cinder \
-    -t volume \
-    -P "http://${CINDER_API_SERVICE_HOST}:${CINDER_API_SERVICE_PORT}/v2/\$(tenant_id)s" \
-    -A "http://${CINDER_API_SERVICE_HOST}:${CINDER_API_SERVICE_PORT}/v2/\$(tenant_id)s" \
-    -I "http://${CINDER_API_SERVICE_HOST}:${CINDER_API_SERVICE_PORT}/v2/\$(tenant_id)s"
-
-crux endpoint-create --remove-all \
-    -n cinderv2 \
-    -t volumev2 \
-    -P "http://${CINDER_API_SERVICE_HOST}:${CINDER_API_SERVICE_PORT}/v2/\$(tenant_id)s" \
-    -A "http://${CINDER_API_SERVICE_HOST}:${CINDER_API_SERVICE_PORT}/v2/\$(tenant_id)s" \
-    -I "http://${CINDER_API_SERVICE_HOST}:${CINDER_API_SERVICE_PORT}/v2/\$(tenant_id)s"
-
-# Logging
-crudini --set $cfg \
-        DEFAULT \
-        log_file \
-        "${CINDER_API_LOG_FILE}"
-
-# API Configuration
-crudini --set $cfg \
-        DEFAULT \
-        osapi_volume_listen \
-        "${CINDER_API_SERVICE_LISTEN}"
-
-crudini --set $cfg \
-        DEFAULT \
-        osapi_volume_listen_port \
-        "${CINDER_API_SERVICE_PORT}"
-
-crudini --set $cfg \
-        DEFAULT \
-        enable_v1_api \
-        "false"
-
-crudini --set $cfg \
-        DEFAULT \
-        enable_v2_api \
-        "true"
-
-echo "Starting cinder-api"
-exec /usr/bin/cinder-api --config-file $cfg
+exec $CMD $ARGS
diff --git a/docker/common/cinder-app/cinder-backup/config-external.sh b/docker/common/cinder-app/cinder-backup/config-external.sh
new file mode 100644
index 0000000000..b3d2582517
--- /dev/null
+++ b/docker/common/cinder-app/cinder-backup/config-external.sh
@@ -0,0 +1,9 @@
+OURCE="/opt/kolla/cinder/cinder.conf"
+TARGET="/etc/cinder/cinder.conf"
+OWNER="cinder"
+
+if [[ -f "$SOURCE" ]]; then
+    cp $SOURCE $TARGET
+    chown ${OWNER}: $TARGET
+    chmod 0644 $TARGET
+fi
diff --git a/docker/common/cinder-app/cinder-backup/config-internal.sh b/docker/common/cinder-app/cinder-backup/config-internal.sh
new file mode 100644
index 0000000000..3227ddab29
--- /dev/null
+++ b/docker/common/cinder-app/cinder-backup/config-internal.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+
+set -e
+
+. /opt/kolla/kolla-common.sh
+. /opt/kolla/config-cinder.sh
+
+check_required_vars CINDER_BACKUP_DRIVER CINDER_BACKUP_MANAGER \
+                    CINDER_BACKUP_API_CLASS CINDER_BACKUP_NAME_TEMPLATE
+
+cfg=/etc/cinder/cinder.conf
+
+# volume backup configuration
+crudini --set $cfg \
+        DEFAULT \
+        backup_driver \
+        "${CINDER_BACKUP_DRIVER}"
+crudini --set $cfg \
+        DEFAULT \
+        backup_topic \
+        "cinder-backup"
+crudini --set $cfg \
+        DEFAULT \
+        backup_manager \
+        "${CINDER_BACKUP_MANAGER}"
+crudini --set $cfg \
+        DEFAULT \
+        backup_api_class \
+        "${CINDER_BACKUP_API_CLASS}"
+crudini --set $cfg \
+        DEFAULT \
+        backup_name_template \
+        "${CINDER_BACKUP_NAME_TEMPLATE}"
+
+# https://bugs.launchpad.net/kolla/+bug/1461635
+# Cinder requires mounting /dev in the cinder-volume, nova-compute,
+# and libvirt containers.  If /dev/pts/ptmx does not have proper permissions
+# on the host, then libvirt will fail to boot an instance.
+# This is a bug in Docker where it is not correctly mounting /dev/pts
+# Tech Debt tracker: https://bugs.launchpad.net/kolla/+bug/1468962
+# **Temporary fix**
+chmod 666 /dev/pts/ptmx
+
+echo "Starting cinder-backup"
+exec /usr/bin/cinder-backup --config-file $cfg
diff --git a/docker/common/cinder-app/cinder-backup/start.sh b/docker/common/cinder-app/cinder-backup/start.sh
index 3227ddab29..1cc902db67 100755
--- a/docker/common/cinder-app/cinder-backup/start.sh
+++ b/docker/common/cinder-app/cinder-backup/start.sh
@@ -1,45 +1,14 @@
 #!/bin/bash
 
-set -e
+set -o errexit
 
-. /opt/kolla/kolla-common.sh
-. /opt/kolla/config-cinder.sh
+CMD="/usr/bin/cinder-backup"
+ARGS=""
 
-check_required_vars CINDER_BACKUP_DRIVER CINDER_BACKUP_MANAGER \
-                    CINDER_BACKUP_API_CLASS CINDER_BACKUP_NAME_TEMPLATE
+# Loading common functions.
+source /opt/kolla/kolla-common.sh
 
-cfg=/etc/cinder/cinder.conf
+# Config-internal script exec out of this function, it does not return here.
+set_configs
 
-# volume backup configuration
-crudini --set $cfg \
-        DEFAULT \
-        backup_driver \
-        "${CINDER_BACKUP_DRIVER}"
-crudini --set $cfg \
-        DEFAULT \
-        backup_topic \
-        "cinder-backup"
-crudini --set $cfg \
-        DEFAULT \
-        backup_manager \
-        "${CINDER_BACKUP_MANAGER}"
-crudini --set $cfg \
-        DEFAULT \
-        backup_api_class \
-        "${CINDER_BACKUP_API_CLASS}"
-crudini --set $cfg \
-        DEFAULT \
-        backup_name_template \
-        "${CINDER_BACKUP_NAME_TEMPLATE}"
-
-# https://bugs.launchpad.net/kolla/+bug/1461635
-# Cinder requires mounting /dev in the cinder-volume, nova-compute,
-# and libvirt containers.  If /dev/pts/ptmx does not have proper permissions
-# on the host, then libvirt will fail to boot an instance.
-# This is a bug in Docker where it is not correctly mounting /dev/pts
-# Tech Debt tracker: https://bugs.launchpad.net/kolla/+bug/1468962
-# **Temporary fix**
-chmod 666 /dev/pts/ptmx
-
-echo "Starting cinder-backup"
-exec /usr/bin/cinder-backup --config-file $cfg
+exec $CMD $ARGS
diff --git a/docker/common/cinder-app/cinder-scheduler/config-external.sh b/docker/common/cinder-app/cinder-scheduler/config-external.sh
new file mode 100644
index 0000000000..5f57ab939a
--- /dev/null
+++ b/docker/common/cinder-app/cinder-scheduler/config-external.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+SOURCE="/opt/kolla/cinder/cinder.conf"
+TARGET="/etc/cinder/cinder.conf"
+OWNER="cinder"
+
+if [[ -f "$SOURCE" ]]; then
+    cp $SOURCE $TARGET
+    chown ${OWNER}: $TARGET
+    chmod 0644 $TARGET
+fi
diff --git a/docker/common/cinder-app/cinder-scheduler/config-internal.sh b/docker/common/cinder-app/cinder-scheduler/config-internal.sh
new file mode 100644
index 0000000000..54df779834
--- /dev/null
+++ b/docker/common/cinder-app/cinder-scheduler/config-internal.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+
+set -e
+
+. /opt/kolla/kolla-common.sh
+. /opt/kolla/config-cinder.sh
+
+fail_unless_db
+
+check_required_vars MARIADB_SERVICE_HOST DB_ROOT_PASSWORD \
+                    CINDER_DB_NAME CINDER_DB_USER CINDER_DB_PASSWORD \
+                    INIT_CINDER_DB
+
+cfg=/etc/cinder/cinder.conf
+
+if [ "${INIT_CINDER_DB}" == "true" ]; then
+    mysql -h ${MARIADB_SERVICE_HOST} -u root -p${DB_ROOT_PASSWORD} mysql <<EOF
+CREATE DATABASE IF NOT EXISTS ${CINDER_DB_NAME};
+GRANT ALL PRIVILEGES ON ${CINDER_DB_NAME}.* TO
+'${CINDER_DB_USER}'@'%' IDENTIFIED BY '${CINDER_DB_PASSWORD}'
+EOF
+
+    su -s /bin/sh -c "cinder-manage db sync" cinder
+fi
+
+crudini --set $cfg \
+    DEFAULT \
+    log_file \
+    "${CINDER_SCHEDULER_LOG_FILE}"
+
+echo "Starting cinder-scheduler"
+exec /usr/bin/cinder-scheduler --config-file $cfg
diff --git a/docker/common/cinder-app/cinder-scheduler/start.sh b/docker/common/cinder-app/cinder-scheduler/start.sh
index 54df779834..94c87dc13b 100755
--- a/docker/common/cinder-app/cinder-scheduler/start.sh
+++ b/docker/common/cinder-app/cinder-scheduler/start.sh
@@ -1,32 +1,14 @@
 #!/bin/bash
 
-set -e
+set -o errexit
 
-. /opt/kolla/kolla-common.sh
-. /opt/kolla/config-cinder.sh
+CMD="/usr/bin/cinder-scheduler"
+ARGS=""
 
-fail_unless_db
+# Loading common functions.
+source /opt/kolla/kolla-common.sh
 
-check_required_vars MARIADB_SERVICE_HOST DB_ROOT_PASSWORD \
-                    CINDER_DB_NAME CINDER_DB_USER CINDER_DB_PASSWORD \
-                    INIT_CINDER_DB
+# Config-internal script exec out of this function, it does not return here.
+set_configs
 
-cfg=/etc/cinder/cinder.conf
-
-if [ "${INIT_CINDER_DB}" == "true" ]; then
-    mysql -h ${MARIADB_SERVICE_HOST} -u root -p${DB_ROOT_PASSWORD} mysql <<EOF
-CREATE DATABASE IF NOT EXISTS ${CINDER_DB_NAME};
-GRANT ALL PRIVILEGES ON ${CINDER_DB_NAME}.* TO
-'${CINDER_DB_USER}'@'%' IDENTIFIED BY '${CINDER_DB_PASSWORD}'
-EOF
-
-    su -s /bin/sh -c "cinder-manage db sync" cinder
-fi
-
-crudini --set $cfg \
-    DEFAULT \
-    log_file \
-    "${CINDER_SCHEDULER_LOG_FILE}"
-
-echo "Starting cinder-scheduler"
-exec /usr/bin/cinder-scheduler --config-file $cfg
+exec $CMD $ARGS
diff --git a/docker/common/cinder-app/cinder-volume/config-external.sh b/docker/common/cinder-app/cinder-volume/config-external.sh
new file mode 100644
index 0000000000..5f57ab939a
--- /dev/null
+++ b/docker/common/cinder-app/cinder-volume/config-external.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+SOURCE="/opt/kolla/cinder/cinder.conf"
+TARGET="/etc/cinder/cinder.conf"
+OWNER="cinder"
+
+if [[ -f "$SOURCE" ]]; then
+    cp $SOURCE $TARGET
+    chown ${OWNER}: $TARGET
+    chmod 0644 $TARGET
+fi
diff --git a/docker/common/cinder-app/cinder-volume/config-internal.sh b/docker/common/cinder-app/cinder-volume/config-internal.sh
new file mode 100644
index 0000000000..0561974253
--- /dev/null
+++ b/docker/common/cinder-app/cinder-volume/config-internal.sh
@@ -0,0 +1,84 @@
+#!/bin/bash
+
+set -e
+
+. /opt/kolla/kolla-common.sh
+. /opt/kolla/config-cinder.sh
+. /opt/kolla/volume-group-create.sh
+
+check_required_vars CINDER_VOLUME_API_LISTEN ISCSI_HELPER ISCSI_IP_ADDRESS \
+                    CINDER_VOLUME_GROUP CINDER_LVM_LO_VOLUME_SIZE \
+                    CINDER_VOLUME_BACKEND_NAME CINDER_VOLUME_DRIVER \
+                    CINDER_ENABLED_BACKEND
+
+cfg=/etc/cinder/cinder.conf
+
+# Logging
+crudini --set $cfg \
+    DEFAULT \
+    log_file \
+    "${CINDER_VOLUME_LOG_FILE}"
+
+# IP address on which OpenStack Volume API listens
+crudini --set $cfg \
+    DEFAULT \
+    osapi_volume_listen \
+    "${CINDER_VOLUME_API_LISTEN}"
+
+# The IP address that the iSCSI daemon is listening on
+crudini --set $cfg \
+    DEFAULT \
+    iscsi_ip_address \
+    "${ISCSI_IP_ADDRESS}"
+
+# Set to false when using loopback devices (testing)
+crudini --set $cfg \
+    DEFAULT \
+    secure_delete \
+    "false"
+
+crudini --set $cfg \
+    DEFAULT \
+    enabled_backends \
+    "${CINDER_ENABLED_BACKEND}"
+
+crudini --set $cfg \
+    lvm57 \
+    iscsi_helper \
+    "${ISCSI_HELPER}"
+
+crudini --set $cfg \
+    lvm57 \
+    volume_group \
+    "${CINDER_VOLUME_GROUP}"
+
+crudini --set $cfg \
+    lvm57 \
+    volume_driver \
+    "${CINDER_VOLUME_DRIVER}"
+
+crudini --set $cfg \
+    lvm57 \
+    iscsi_ip_address \
+    "${ISCSI_IP_ADDRESS}"
+
+crudini --set $cfg \
+    lvm57 \
+    volume_backend_name \
+    "${CINDER_VOLUME_BACKEND_NAME}"
+
+sed -i 's/udev_sync = 1/udev_sync = 0/' /etc/lvm/lvm.conf
+sed -i 's/udev_rules = 1/udev_rules = 0/' /etc/lvm/lvm.conf
+sed -i 's/use_lvmetad = 1/use_lvmetad = 0/' /etc/lvm/lvm.conf
+
+# https://bugs.launchpad.net/kolla/+bug/1461635
+# Cinder requires mounting /dev in the cinder-volume, nova-compute,
+# and libvirt containers.  If /dev/pts/ptmx does not have proper permissions
+# on the host, then libvirt will fail to boot an instance.
+# This is a bug in Docker where it is not correctly mounting /dev/pts
+# Tech Debt tracker: https://bugs.launchpad.net/kolla/+bug/1468962
+# **Temporary fix**
+chmod 666 /dev/pts/ptmx
+
+echo "Starting cinder-volume"
+exec /usr/bin/cinder-volume --config-file /etc/cinder/cinder.conf
diff --git a/docker/common/cinder-app/cinder-volume/start.sh b/docker/common/cinder-app/cinder-volume/start.sh
index 0561974253..f6acf61e0c 100755
--- a/docker/common/cinder-app/cinder-volume/start.sh
+++ b/docker/common/cinder-app/cinder-volume/start.sh
@@ -1,84 +1,14 @@
 #!/bin/bash
 
-set -e
+set -o errexit
 
-. /opt/kolla/kolla-common.sh
-. /opt/kolla/config-cinder.sh
-. /opt/kolla/volume-group-create.sh
+CMD="/usr/bin/cinder-volume"
+ARGS=""
 
-check_required_vars CINDER_VOLUME_API_LISTEN ISCSI_HELPER ISCSI_IP_ADDRESS \
-                    CINDER_VOLUME_GROUP CINDER_LVM_LO_VOLUME_SIZE \
-                    CINDER_VOLUME_BACKEND_NAME CINDER_VOLUME_DRIVER \
-                    CINDER_ENABLED_BACKEND
+# Loading common functions.
+source /opt/kolla/kolla-common.sh
 
-cfg=/etc/cinder/cinder.conf
+# Config-internal script exec out of this function, it does not return here.
+set_configs
 
-# Logging
-crudini --set $cfg \
-    DEFAULT \
-    log_file \
-    "${CINDER_VOLUME_LOG_FILE}"
-
-# IP address on which OpenStack Volume API listens
-crudini --set $cfg \
-    DEFAULT \
-    osapi_volume_listen \
-    "${CINDER_VOLUME_API_LISTEN}"
-
-# The IP address that the iSCSI daemon is listening on
-crudini --set $cfg \
-    DEFAULT \
-    iscsi_ip_address \
-    "${ISCSI_IP_ADDRESS}"
-
-# Set to false when using loopback devices (testing)
-crudini --set $cfg \
-    DEFAULT \
-    secure_delete \
-    "false"
-
-crudini --set $cfg \
-    DEFAULT \
-    enabled_backends \
-    "${CINDER_ENABLED_BACKEND}"
-
-crudini --set $cfg \
-    lvm57 \
-    iscsi_helper \
-    "${ISCSI_HELPER}"
-
-crudini --set $cfg \
-    lvm57 \
-    volume_group \
-    "${CINDER_VOLUME_GROUP}"
-
-crudini --set $cfg \
-    lvm57 \
-    volume_driver \
-    "${CINDER_VOLUME_DRIVER}"
-
-crudini --set $cfg \
-    lvm57 \
-    iscsi_ip_address \
-    "${ISCSI_IP_ADDRESS}"
-
-crudini --set $cfg \
-    lvm57 \
-    volume_backend_name \
-    "${CINDER_VOLUME_BACKEND_NAME}"
-
-sed -i 's/udev_sync = 1/udev_sync = 0/' /etc/lvm/lvm.conf
-sed -i 's/udev_rules = 1/udev_rules = 0/' /etc/lvm/lvm.conf
-sed -i 's/use_lvmetad = 1/use_lvmetad = 0/' /etc/lvm/lvm.conf
-
-# https://bugs.launchpad.net/kolla/+bug/1461635
-# Cinder requires mounting /dev in the cinder-volume, nova-compute,
-# and libvirt containers.  If /dev/pts/ptmx does not have proper permissions
-# on the host, then libvirt will fail to boot an instance.
-# This is a bug in Docker where it is not correctly mounting /dev/pts
-# Tech Debt tracker: https://bugs.launchpad.net/kolla/+bug/1468962
-# **Temporary fix**
-chmod 666 /dev/pts/ptmx
-
-echo "Starting cinder-volume"
-exec /usr/bin/cinder-volume --config-file /etc/cinder/cinder.conf
+exec $CMD $ARGS