summaryrefslogtreecommitdiffstats
path: root/hammer.py
diff options
context:
space:
mode:
authorAndrei Pavel <andrei@isc.org>2021-04-20 08:04:42 +0200
committerAndrei Pavel <andrei@isc.org>2021-04-20 08:04:42 +0200
commit8fb1ea327b395887e531d17e0868d1d4b7bdb9c0 (patch)
tree55682063a5423d1a282594f9629b2cc26bb359bd /hammer.py
parent[#1813] hammer: add freeradius-client version for ubuntu 20.10 (diff)
downloadkea-8fb1ea327b395887e531d17e0868d1d4b7bdb9c0.tar.xz
kea-8fb1ea327b395887e531d17e0868d1d4b7bdb9c0.zip
[#1814] hammer: get pg_hba location automatically
Diffstat (limited to 'hammer.py')
-rwxr-xr-xhammer.py30
1 files changed, 19 insertions, 11 deletions
diff --git a/hammer.py b/hammer.py
index 90b3345994..895fb42b2e 100755
--- a/hammer.py
+++ b/hammer.py
@@ -1038,6 +1038,19 @@ def _configure_mysql(system, revision, features):
execute(cmd)
+def _enable_and_restart_postgresql(system):
+ if system == 'freebsd':
+ # redirecting output from start script to /dev/null otherwise the postgresql rc.d script will hang
+ # calling restart instead of start allow hammer.py to pass even if postgresql is already installed
+ execute('sudo service postgresql restart > /dev/null')
+ elif system == 'alpine':
+ execute('sudo rc-update add postgresql')
+ execute('sudo /etc/init.d/postgresql restart')
+ else:
+ execute('sudo systemctl enable postgresql.service')
+ execute('sudo systemctl restart postgresql.service')
+
+
def _configure_pgsql(system, features):
""" Configure PostgreSQL DB """
if system in ['fedora', 'centos']:
@@ -1053,19 +1066,14 @@ def _configure_pgsql(system, features):
execute('sudo sysrc postgresql_enable="yes"')
execute('[ ! -d /var/db/postgres/data11 ] && sudo /usr/local/etc/rc.d/postgresql initdb || true')
+ _enable_and_restart_postgresql(system)
+
# Change auth-method to 'trust' on local connections.
- execute("sudo sed -i.bak 's/^local\(.*\) [a-z0-9]*$/local\\1 trust/g' $(find /etc/postgresql -name pg_hba.conf -type f)")
+ _, output = execute("printf 'SHOW hba_file' | sudo -u postgres psql -t postgres | xargs", capture=True)
+ hba_file = output.rstrip()
+ execute("sudo sed -i.bak 's/^local\(.*\) [a-z0-9]*$/local\\1 trust/g' '{}'".format(hba_file))
- if system == 'freebsd':
- # redirecting output from start script to /dev/null otherwise the postgresql rc.d script will hang
- # calling restart instead of start allow hammer.py to pass even if postgresql is already installed
- execute('sudo service postgresql restart > /dev/null')
- elif system == 'alpine':
- execute('sudo rc-update add postgresql')
- execute('sudo /etc/init.d/postgresql restart')
- else:
- execute('sudo systemctl enable postgresql.service')
- execute('sudo systemctl restart postgresql.service')
+ _enable_and_restart_postgresql(system)
cmd = """bash -c \"cat <<EOF | sudo -u postgres psql postgres
DROP DATABASE IF EXISTS keatest;