Merge "Added postgres bin path to cmd calls"
This commit is contained in:
commit
ced5bbfec7
@ -49,6 +49,7 @@ from oslo_log import log as logging
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
POSTGRES_BIN = utils.get_postgres_bin()
|
||||
POSTGRES_MOUNT_PATH = '/mnt/postgresql'
|
||||
POSTGRES_DUMP_MOUNT_PATH = '/mnt/db_dump'
|
||||
DB_CONNECTION_FORMAT = "connection=postgresql://%s:%s@127.0.0.1/%s\n"
|
||||
@ -471,7 +472,9 @@ def create_database():
|
||||
|
||||
db_create_commands = [
|
||||
# Configure new data directory for postgres
|
||||
'sudo -u postgres initdb -D ' + utils.POSTGRES_DATA_DIR,
|
||||
'sudo -u postgres {} -D {}'.format(
|
||||
os.path.join(POSTGRES_BIN, 'initdb'),
|
||||
utils.POSTGRES_DATA_DIR),
|
||||
'chmod -R 700 ' + utils.POSTGRES_DATA_DIR,
|
||||
'chown -R postgres ' + utils.POSTGRES_DATA_DIR,
|
||||
]
|
||||
@ -901,14 +904,15 @@ def upgrade_controller(from_release, to_release):
|
||||
|
||||
# Start the postgres server
|
||||
try:
|
||||
subprocess.check_call(['sudo',
|
||||
'-u',
|
||||
'postgres',
|
||||
'pg_ctl',
|
||||
'-D',
|
||||
utils.POSTGRES_DATA_DIR,
|
||||
'start'],
|
||||
stdout=devnull)
|
||||
subprocess.check_call([
|
||||
'sudo',
|
||||
'-u',
|
||||
'postgres',
|
||||
os.path.join(POSTGRES_BIN, 'pg_ctl'),
|
||||
'-D',
|
||||
utils.POSTGRES_DATA_DIR,
|
||||
'start'],
|
||||
stdout=devnull)
|
||||
except subprocess.CalledProcessError:
|
||||
LOG.exception("Failed to start postgres service")
|
||||
raise
|
||||
@ -976,14 +980,15 @@ def upgrade_controller(from_release, to_release):
|
||||
|
||||
# Stop postgres server
|
||||
try:
|
||||
subprocess.check_call(['sudo',
|
||||
'-u',
|
||||
'postgres',
|
||||
'pg_ctl',
|
||||
'-D',
|
||||
utils.POSTGRES_DATA_DIR,
|
||||
'stop'],
|
||||
stdout=devnull)
|
||||
subprocess.check_call([
|
||||
'sudo',
|
||||
'-u',
|
||||
'postgres',
|
||||
os.path.join(POSTGRES_BIN, 'pg_ctl'),
|
||||
'-D',
|
||||
utils.POSTGRES_DATA_DIR,
|
||||
'stop'],
|
||||
stdout=devnull)
|
||||
except subprocess.CalledProcessError:
|
||||
LOG.exception("Failed to stop postgres service")
|
||||
raise
|
||||
|
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2016-2021 Wind River Systems, Inc.
|
||||
# Copyright (c) 2016-2022 Wind River Systems, Inc.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
@ -386,3 +386,14 @@ def get_keystone_project_id(project_name):
|
||||
return project_id['id']
|
||||
else:
|
||||
return project_id
|
||||
|
||||
|
||||
def get_postgres_bin():
|
||||
""" Get the path to the postgres binaries"""
|
||||
|
||||
try:
|
||||
return subprocess.check_output(
|
||||
['pg_config', '--bindir']).decode().rstrip('\n')
|
||||
except subprocess.CalledProcessError:
|
||||
LOG.exception("Failed to get postgres bin directory.")
|
||||
raise
|
||||
|
Loading…
x
Reference in New Issue
Block a user