Tweak logic for setting PostgreSQL listen_addresses

this still isn't right, but i'm calling this a savepoint at least
This commit is contained in:
Lance Edgar 2022-07-25 19:52:32 -05:00
parent f97401009e
commit 303f650a0b

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2021 Lance Edgar
# Copyright © 2010-2022 Lance Edgar
#
# This file is part of Rattail.
#
@ -26,6 +26,7 @@ Fabric Library for PostgreSQL
import os
import re
import sys
from rattail_fabric2 import apt, append, contains, sed, uncomment
@ -53,8 +54,8 @@ def set_listen_addresses(c, *addresses):
Overwrite the `listen_addresses` config setting in `postgresql.conf`.
"""
version = get_version(c)
if 12 <= version < 13:
version = 12
if version > 12:
version = int(version)
addresses = ','.join(addresses)
# TODO: this does not seem to work, so cannot do this..? need to
@ -62,12 +63,22 @@ def set_listen_addresses(c, *addresses):
# addresses = addresses.replace('*', '\\\\*')
if not contains(c, '/etc/postgresql/{}/main/postgresql.conf'.format(version),
"listen_addresses = '{}'".format(addresses)):
"listen_addresses = '{}'".format(addresses),
exact=True):
uncomment(c, '/etc/postgresql/{}/main/postgresql.conf'.format(version),
r'^#listen_addresses = .*',
r'^#listen_addresses\s*=.*',
use_sudo=True)
if addresses == '*':
print("\n\nYou requested a wildcard ('*') as the listen_addresses "
"value for PostgreSQL. Unfortunately our logic is not yet "
"sufficient to handle that scenario, so you must manually "
"edit this file:\n\n"
" /etc/postgresql/{}/main/postgresql.conf\n\n"
"And somewhere in there add exactly the following:\n\n"
" listen_addresses = '*'\n\n".format(version))
sys.exit(1)
sed(c, '/etc/postgresql/{}/main/postgresql.conf'.format(version),
r'listen_addresses = .*',
r'listen_addresses\s*=.*',
"listen_addresses = '{}'".format(addresses),
use_sudo=True)
restart(c)
@ -78,8 +89,8 @@ def add_hba_entry(c, entry):
Add an entry to the `pg_hba.conf` file.
"""
version = get_version(c)
if 12 <= version < 13:
version = 12
if version > 12:
version = int(version)
if not contains(c, '/etc/postgresql/{}/main/pg_hba.conf'.format(version),
entry, use_sudo=True):