From e21c68a69e476debaf3dc88f022cf4c1bce9ce9e Mon Sep 17 00:00:00 2001
From: Swapnil Kulkarni <me@coolsvap.net>
Date: Mon, 6 Jul 2015 05:24:47 +0000
Subject: [PATCH] Add config-internal/config-external for horizon

Partially Implements: Blueprint standard-start

Change-Id: I8a88572a4390824787c663014e6eae52dbb04648
---
 docker/centos/binary/horizon/Dockerfile       |  1 +
 .../centos/binary/horizon/config-external.sh  |  1 +
 .../centos/binary/horizon/config-internal.sh  |  1 +
 docker/common/horizon/config-external.sh      | 11 ++++++
 docker/common/horizon/config-internal.sh      | 36 ++++++++++++++++++
 docker/common/horizon/start.sh                | 38 ++++---------------
 6 files changed, 58 insertions(+), 30 deletions(-)
 create mode 120000 docker/centos/binary/horizon/config-external.sh
 create mode 120000 docker/centos/binary/horizon/config-internal.sh
 create mode 100644 docker/common/horizon/config-external.sh
 create mode 100644 docker/common/horizon/config-internal.sh

diff --git a/docker/centos/binary/horizon/Dockerfile b/docker/centos/binary/horizon/Dockerfile
index 2c34ee03ab..79f9b8bd65 100644
--- a/docker/centos/binary/horizon/Dockerfile
+++ b/docker/centos/binary/horizon/Dockerfile
@@ -12,5 +12,6 @@ RUN yum -y install \
 # https://bugzilla.redhat.com/show_bug.cgi?id=1219006
 
 ADD ./start.sh /start.sh
+COPY config-internal.sh config-external.sh /opt/kolla/
 
 CMD ["/start.sh"]
diff --git a/docker/centos/binary/horizon/config-external.sh b/docker/centos/binary/horizon/config-external.sh
new file mode 120000
index 0000000000..19b799f7b9
--- /dev/null
+++ b/docker/centos/binary/horizon/config-external.sh
@@ -0,0 +1 @@
+../../../common/horizon/config-external.sh
\ No newline at end of file
diff --git a/docker/centos/binary/horizon/config-internal.sh b/docker/centos/binary/horizon/config-internal.sh
new file mode 120000
index 0000000000..82e83c796f
--- /dev/null
+++ b/docker/centos/binary/horizon/config-internal.sh
@@ -0,0 +1 @@
+../../../common/horizon/config-internal.sh
\ No newline at end of file
diff --git a/docker/common/horizon/config-external.sh b/docker/common/horizon/config-external.sh
new file mode 100644
index 0000000000..519a28b06b
--- /dev/null
+++ b/docker/common/horizon/config-external.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+SOURCE="/etc/openstack-dashboard/local_settings"
+TARGET="/etc/openstack-dashboard/local_settings"
+
+OWNER="horizon"
+
+if [[ -f "$SOURCE" ]]; then
+    cp $SOURCE $TARGET
+    chown ${OWNER}: $TARGET
+    chmod 0644 $TARGET
+fi
diff --git a/docker/common/horizon/config-internal.sh b/docker/common/horizon/config-internal.sh
new file mode 100644
index 0000000000..4e720bb879
--- /dev/null
+++ b/docker/common/horizon/config-internal.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+set -e
+
+: ${HORIZON_KEYSTONE_USER:=horizon}
+
+. /opt/kolla/kolla-common.sh
+
+fail_unless_os_service_running keystone
+fail_unless_os_service_running glance
+fail_unless_os_service_running nova
+
+export SERVICE_TOKEN="${KEYSTONE_ADMIN_TOKEN}"
+export SERVICE_ENDPOINT="${KEYSTONE_AUTH_PROTOCOL}://${KEYSTONE_ADMIN_SERVICE_HOST}:35357/v2.0"
+
+cfg=/etc/openstack-dashboard/local_settings
+httpdcfg=/etc/httpd/conf.d/openstack-dashboard.conf
+
+sed -ri 's/ALLOWED_HOSTS = \['\''horizon.example.com'\'', '\''localhost'\''\]/ALLOWED_HOSTS = \['\''*'\'', \]/' /etc/openstack-dashboard/local_settings
+
+sed -ri 's/OPENSTACK_KEYSTONE_URL = \"http:\/\/%s:5000\/v2.0\" % OPENSTACK_HOST/OPENSTACK_KEYSTONE_URL = \"http:\/\/'"$KEYSTONE_PUBLIC_SERVICE_HOST"':5000\/v2.0\"/' /etc/openstack-dashboard/local_settings
+
+sed -ri 's/OPENSTACK_HOST = \"127.0.0.1\"/OPENSTACK_HOST = \"'"$KEYSTONE_PUBLIC_SERVICE_HOST"'\" /' /etc/openstack-dashboard/local_settings
+
+# Make sure we launch horizon using the default value for WEBROOT, which is
+# '/'.
+sed -ri '/^WEBROOT =.+/d' $cfg
+sed -ri 's,^(WSGIScriptAlias) /dashboard (/usr/share/openstack-dashboard/openstack_dashboard/wsgi/django.wsgi),\1 / \2,' $httpdcfg
+sed -ri 's,^(Alias /dashboard)(/static /usr/share/openstack-dashboard/static),Alias \2,' $httpdcfg
+
+# This step is required because of:
+# https://bugzilla.redhat.com/show_bug.cgi?id=1220070
+# Running this in the Dockerfile didn't fix the HTTP/500 as a result of the
+# missing compress action.
+python /usr/share/openstack-dashboard/manage.py compress
+
+/usr/sbin/httpd -DFOREGROUND
diff --git a/docker/common/horizon/start.sh b/docker/common/horizon/start.sh
index 4e720bb879..756c6311a4 100755
--- a/docker/common/horizon/start.sh
+++ b/docker/common/horizon/start.sh
@@ -1,36 +1,14 @@
 #!/bin/bash
-set -e
 
-: ${HORIZON_KEYSTONE_USER:=horizon}
+set -o errexit
 
-. /opt/kolla/kolla-common.sh
+CMD="/usr/sbin/httpd -DFOREGROUND"
+ARGS=""
 
-fail_unless_os_service_running keystone
-fail_unless_os_service_running glance
-fail_unless_os_service_running nova
+# Loading common functions.
+source /opt/kolla/kolla-common.sh
 
-export SERVICE_TOKEN="${KEYSTONE_ADMIN_TOKEN}"
-export SERVICE_ENDPOINT="${KEYSTONE_AUTH_PROTOCOL}://${KEYSTONE_ADMIN_SERVICE_HOST}:35357/v2.0"
+# Config-internal script exec out of this function, it does not return here.
+set_configs
 
-cfg=/etc/openstack-dashboard/local_settings
-httpdcfg=/etc/httpd/conf.d/openstack-dashboard.conf
-
-sed -ri 's/ALLOWED_HOSTS = \['\''horizon.example.com'\'', '\''localhost'\''\]/ALLOWED_HOSTS = \['\''*'\'', \]/' /etc/openstack-dashboard/local_settings
-
-sed -ri 's/OPENSTACK_KEYSTONE_URL = \"http:\/\/%s:5000\/v2.0\" % OPENSTACK_HOST/OPENSTACK_KEYSTONE_URL = \"http:\/\/'"$KEYSTONE_PUBLIC_SERVICE_HOST"':5000\/v2.0\"/' /etc/openstack-dashboard/local_settings
-
-sed -ri 's/OPENSTACK_HOST = \"127.0.0.1\"/OPENSTACK_HOST = \"'"$KEYSTONE_PUBLIC_SERVICE_HOST"'\" /' /etc/openstack-dashboard/local_settings
-
-# Make sure we launch horizon using the default value for WEBROOT, which is
-# '/'.
-sed -ri '/^WEBROOT =.+/d' $cfg
-sed -ri 's,^(WSGIScriptAlias) /dashboard (/usr/share/openstack-dashboard/openstack_dashboard/wsgi/django.wsgi),\1 / \2,' $httpdcfg
-sed -ri 's,^(Alias /dashboard)(/static /usr/share/openstack-dashboard/static),Alias \2,' $httpdcfg
-
-# This step is required because of:
-# https://bugzilla.redhat.com/show_bug.cgi?id=1220070
-# Running this in the Dockerfile didn't fix the HTTP/500 as a result of the
-# missing compress action.
-python /usr/share/openstack-dashboard/manage.py compress
-
-/usr/sbin/httpd -DFOREGROUND
+exec $CMD $ARGS