From 440c035d808ee87acdd445f221373eacd9bd710f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Diemer?= <stephane.diemer@ubicast.eu> Date: Fri, 2 Dec 2016 08:51:12 +0100 Subject: [PATCH] Moved config download in a dedicated step (refs #19471). --- 21.Download_configuration_file/0_setup.sh | 14 +++++++ 21.Initialize_configuration_file/0_setup.sh | 35 ----------------- 22.Initialize_configuration_file/0_setup.sh | 39 +++++++++++++++++++ .../0_setup.sh | 0 .../0_setup.sh | 0 .../sources16.list | 0 7.Nginx/0_setup.py | 2 +- default-conf.sh | 2 +- launcher.sh | 2 +- 9 files changed, 56 insertions(+), 38 deletions(-) create mode 100755 21.Download_configuration_file/0_setup.sh delete mode 100755 21.Initialize_configuration_file/0_setup.sh create mode 100755 22.Initialize_configuration_file/0_setup.sh rename {22.Initialize_environment => 23.Initialize_environment}/0_setup.sh (100%) rename {23.Initialize_APT => 24.Initialize_APT}/0_setup.sh (100%) rename {23.Initialize_APT => 24.Initialize_APT}/sources16.list (100%) diff --git a/21.Download_configuration_file/0_setup.sh b/21.Download_configuration_file/0_setup.sh new file mode 100755 index 00000000..dc20e09b --- /dev/null +++ b/21.Download_configuration_file/0_setup.sh @@ -0,0 +1,14 @@ +#!/bin/bash +source /root/envsetup/conf.sh + +# Download config file from skyreach +if ( ! test -z ${SKYREACH_API_KEY} ); then + conf_url="https://$SKYREACH_HOST/erp/credentials/$SKYREACH_API_KEY/conf.sh" + if ( curl -I "$conf_url" >/dev/null ); then + wget -q "$conf_url" -O /root/envsetup/conf.sh + source /root/envsetup/conf.sh + else + echo "Failed to download configuration using url:" + echo " $conf_url" + fi +fi diff --git a/21.Initialize_configuration_file/0_setup.sh b/21.Initialize_configuration_file/0_setup.sh deleted file mode 100755 index 3c56e495..00000000 --- a/21.Initialize_configuration_file/0_setup.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -source /root/envsetup/conf.sh - -# Download config file from skyreach -if ( ! test -z ${SKYREACH_API_KEY} ); then - conf_url="https://$SKYREACH_HOST/erp/credentials/$SKYREACH_API_KEY/conf.sh" - if ( curl -I "$conf_url" >/dev/null ); then - wget -q "$conf_url" -O /root/envsetup/conf.sh - source /root/envsetup/conf.sh - else - echo "Failed to download configuration using url:" - echo " $conf_url" - fi -fi - -# Autogenerate missing values -if [ "${MS_ID}" = "" ]; then - MS_ID=$(echo "$(hostname)_msuser") - sed -i "s@^MS_ID=.*@MS_ID='${MS_ID}'@" /root/envsetup/conf.sh -fi -if [ "${MS_API_KEY}" = "" ]; then - MS_API_KEY=$(echo "s$(pwgen 4)-$(pwgen 5)-$(pwgen 5)-$(pwgen 5)-$(pwgen 5)") - # respect API pattern - MS_API_KEY=$(echo $MS_API_KEY | sed "s@[iloILO]@$((${RANDOM} / 10000))@g") - sed -i "s@^MS_API_KEY=.*@MS_API_KEY='${MS_API_KEY}'@" /root/envsetup/conf.sh -fi -if [ "${MS_SECRET}" = "secret" ]; then - MS_SECRET=$(echo "$(pwgen 40)") - sed -i "s@^MS_SECRET=.*@MS_SECRET='${MS_SECRET}'@" /root/envsetup/conf.sh -fi -# Worker IP for whitelist -if [ "${CELERITY_WORKER_IP}" = "" ]; then - CELERITY_WORKER_IP=$(ip addr show | grep inet | grep -v 127 | grep -v ":" | awk -F " " '{print$2}' | awk -F "/" '{print$1}') - sed -i "s@^CELERITY_CELERITY_WORKER_IP=.*@CELERITY_CELERITY_WORKER_IP='${CELERITY_WORKER_IP}'@" /root/envsetup/conf.sh -fi diff --git a/22.Initialize_configuration_file/0_setup.sh b/22.Initialize_configuration_file/0_setup.sh new file mode 100755 index 00000000..a737add2 --- /dev/null +++ b/22.Initialize_configuration_file/0_setup.sh @@ -0,0 +1,39 @@ +#!/bin/bash +source /root/envsetup/conf.sh + +# Autogenerate missing values +if [ "${MS_ID}" = "" ]; then + MS_ID=$(echo "$(hostname)_msuser") + if ( cat "/root/envsetup/conf.sh" | grep "MS_ID" >/dev/null ); then + sed -i "s@^MS_ID=.*@MS_ID='${MS_ID}'@" /root/envsetup/conf.sh + else + echo "MS_ID='${MS_ID}'" > /root/envsetup/conf.sh + fi +fi +if [ "${MS_API_KEY}" = "" ]; then + MS_API_KEY=$(echo "s$(pwgen 4)-$(pwgen 5)-$(pwgen 5)-$(pwgen 5)-$(pwgen 5)") + # respect API pattern + MS_API_KEY=$(echo $MS_API_KEY | sed "s@[iloILO]@$((${RANDOM} / 10000))@g") + if ( cat "/root/envsetup/conf.sh" | grep "MS_API_KEY" >/dev/null ); then + sed -i "s@^MS_API_KEY=.*@MS_API_KEY='${MS_API_KEY}'@" /root/envsetup/conf.sh + else + echo "MS_API_KEY='${MS_API_KEY}'" > /root/envsetup/conf.sh + fi +fi +if [ "${MS_SECRET}" = "secret" ]; then + MS_SECRET=$(echo "$(pwgen 40)") + if ( cat "/root/envsetup/conf.sh" | grep "MS_SECRET" >/dev/null ); then + sed -i "s@^MS_SECRET=.*@MS_SECRET='${MS_SECRET}'@" /root/envsetup/conf.sh + else + echo "MS_SECRET='${MS_SECRET}'" > /root/envsetup/conf.sh + fi +fi +# Worker IP for whitelist +if [ "${CELERITY_WORKER_IP}" = "" ]; then + CELERITY_WORKER_IP=$(ip addr show | grep inet | grep -v 127 | grep -v ":" | awk -F " " '{print$2}' | awk -F "/" '{print$1}') + if ( cat "/root/envsetup/conf.sh" | grep "CELERITY_WORKER_IP" >/dev/null ); then + sed -i "s@^CELERITY_WORKER_IP=.*@CELERITY_WORKER_IP='${CELERITY_WORKER_IP}'@" /root/envsetup/conf.sh + else + echo "CELERITY_WORKER_IP='${CELERITY_WORKER_IP}'" > /root/envsetup/conf.sh + fi +fi diff --git a/22.Initialize_environment/0_setup.sh b/23.Initialize_environment/0_setup.sh similarity index 100% rename from 22.Initialize_environment/0_setup.sh rename to 23.Initialize_environment/0_setup.sh diff --git a/23.Initialize_APT/0_setup.sh b/24.Initialize_APT/0_setup.sh similarity index 100% rename from 23.Initialize_APT/0_setup.sh rename to 24.Initialize_APT/0_setup.sh diff --git a/23.Initialize_APT/sources16.list b/24.Initialize_APT/sources16.list similarity index 100% rename from 23.Initialize_APT/sources16.list rename to 24.Initialize_APT/sources16.list diff --git a/7.Nginx/0_setup.py b/7.Nginx/0_setup.py index 9e8298d0..4eaafae9 100644 --- a/7.Nginx/0_setup.py +++ b/7.Nginx/0_setup.py @@ -45,7 +45,7 @@ def setup(interactive=True): if os.path.exists('/home/msuser/msinstance'): server_name = utils.get_conf('MS_SERVER_NAME') or 'mediaserver' cmds.extend(vhost_write_cmds(dir_path, 'mediaserver-msuser', server_name, - secret=utils.get_conf('MS_SECRET') or 'secret', worker_ip=utils.get_conf('CELERITY_CELERITY_WORKER_IP') or '127.0.1.1')) + secret=utils.get_conf('MS_SECRET') or 'secret', worker_ip=utils.get_conf('CELERITY_WORKER_IP') or '127.0.1.1')) hosts.append(server_name) # Monitor: msmonitor vhost if os.path.exists('/home/msmonitor/msmonitor'): diff --git a/default-conf.sh b/default-conf.sh index c6b37f90..cb003dd6 100644 --- a/default-conf.sh +++ b/default-conf.sh @@ -68,7 +68,7 @@ MYSQL_CONTACT_IP= # -- Celerity -- CELERITY_SIGNING_KEY='test' -CELERITY_CELERITY_WORKER_IP='127.0.1.1' +CELERITY_WORKER_IP='127.0.1.1' # -- Network configuration -- # applied with envsetup-launcher.sh client diff --git a/launcher.sh b/launcher.sh index 8352a560..470a7709 100755 --- a/launcher.sh +++ b/launcher.sh @@ -20,9 +20,9 @@ exec > >(tee -i ${LOGFILE}) init() { python3 /root/envsetup/envsetup.py 1 python3 /root/envsetup/envsetup.py 2 - python3 /root/envsetup/envsetup.py 21 python3 /root/envsetup/envsetup.py 22 python3 /root/envsetup/envsetup.py 23 + python3 /root/envsetup/envsetup.py 24 python3 /root/envsetup/envsetup.py 4 } -- GitLab