From 7c408ae102802a50a5a6e0303de155752cd9350a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Diemer?= <stephane.diemer@ubicast.eu> Date: Tue, 16 Jan 2018 10:50:21 +0100 Subject: [PATCH] Changed postgres setup to set root pwd (refs #24073). --- 2.Common_services/3.PostgreSQL/0_setup.py | 17 +++++++++++++++++ 2.Common_services/3.PostgreSQL/0_setup.sh | 5 ----- 30.Deprecated/4.MySQL/0_setup.py | 8 ++++---- global-conf.sh | 9 ++++----- 4 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 2.Common_services/3.PostgreSQL/0_setup.py delete mode 100755 2.Common_services/3.PostgreSQL/0_setup.sh diff --git a/2.Common_services/3.PostgreSQL/0_setup.py b/2.Common_services/3.PostgreSQL/0_setup.py new file mode 100644 index 00000000..dcfb881d --- /dev/null +++ b/2.Common_services/3.PostgreSQL/0_setup.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +import utils + + +def setup(interactive=True): + db_host = utils.get_conf('DB_HOST') + if db_host and not db_host.startswith('127') and db_host != 'localhost': + utils.log('Skipping postgresql setup because the database host is set to "%s".' % db_host) + return + cmds = [ + 'DEBIAN_FRONTEND=noninteractive apt-get install -y postgresql', + ] + root_pwd = utils.get_conf('DB_PG_ROOT_PWD') + if root_pwd: + cmds.append('sudo su - postgres -c "psql -w -q -A -c "ALTER USER postgres WITH PASSWORD \'%s\';"' % root_pwd) + utils.run_commands(cmds) diff --git a/2.Common_services/3.PostgreSQL/0_setup.sh b/2.Common_services/3.PostgreSQL/0_setup.sh deleted file mode 100755 index 2ad30e68..00000000 --- a/2.Common_services/3.PostgreSQL/0_setup.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -# TODO: use PostgreSQL custom repo - -DEBIAN_FRONTEND=noninteractive apt-get install -y postgresql diff --git a/30.Deprecated/4.MySQL/0_setup.py b/30.Deprecated/4.MySQL/0_setup.py index 669f9c67..954547b1 100644 --- a/30.Deprecated/4.MySQL/0_setup.py +++ b/30.Deprecated/4.MySQL/0_setup.py @@ -13,11 +13,11 @@ def setup(interactive=True): 'cp "%s/override.conf" "/etc/systemd/system/mysql.service.d/override.conf"' % dir_path, '/etc/init.d/mysql restart', ] - MYSQL_ROOT_PWD = utils.get_conf('MYSQL_ROOT_PWD') - if MYSQL_ROOT_PWD: + root_pwd = utils.get_conf('DB_MYSQL_ROOT_PWD') + if root_pwd: # Set password if any - cmds.append('mysqladmin -u root password "%s"' % MYSQL_ROOT_PWD) + cmds.append('mysqladmin -u root password "%s"' % root_pwd) utils.run_commands(cmds) - if not MYSQL_ROOT_PWD: + if not root_pwd: utils.log('No root password was set in the configuration file.\nUse the following command to change it:\n mysqladmin -u root password <pwd>') diff --git a/global-conf.sh b/global-conf.sh index 998177f1..fb952763 100644 --- a/global-conf.sh +++ b/global-conf.sh @@ -67,12 +67,11 @@ CM_ADMIN_PWD='test' CACHE_SERVER_NAME= CACHE_SOURCE= -# -- MySQL -- +# -- Database -- +DB_HOST= # if no password is set, it will not be changed or set -MYSQL_ROOT_PWD= -MYSQL_HOST= -# client IP seen by mysql server, use commas to separate values -MYSQL_CONTACT_IP= +DB_PG_ROOT_PWD= +DB_MYSQL_ROOT_PWD= # -- Celerity -- CELERITY_SIGNING_KEY='test' -- GitLab