Fix logic to bind postgres to all network interfaces

ugh, finally solved this
This commit is contained in:
Lance Edgar 2023-01-07 17:22:21 -06:00
parent 5fcfc91d83
commit 8c556e6176
2 changed files with 10 additions and 16 deletions

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2022 Lance Edgar # Copyright © 2010-2023 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -26,7 +26,6 @@ Fabric Library for PostgreSQL
import os import os
import re import re
import sys
from rattail_fabric2 import apt, append, contains, sed, uncomment from rattail_fabric2 import apt, append, contains, sed, uncomment
@ -58,29 +57,20 @@ def set_listen_addresses(c, *addresses):
version = int(version) version = int(version)
addresses = ','.join(addresses) addresses = ','.join(addresses)
# TODO: this does not seem to work, so cannot do this..? need to
# figure it out, since it's the whole reason i added this function
# addresses = addresses.replace('*', '\\\\*')
if not contains(c, '/etc/postgresql/{}/main/postgresql.conf'.format(version), if not contains(c, '/etc/postgresql/{}/main/postgresql.conf'.format(version),
"listen_addresses = '{}'".format(addresses), "listen_addresses = '{}'".format(addresses),
exact=True): exact=True):
uncomment(c, '/etc/postgresql/{}/main/postgresql.conf'.format(version), uncomment(c, '/etc/postgresql/{}/main/postgresql.conf'.format(version),
r'^#listen_addresses\s*=.*', r'^# *listen_addresses\s*=.*',
use_sudo=True) 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), sed(c, '/etc/postgresql/{}/main/postgresql.conf'.format(version),
r'listen_addresses\s*=.*', r'listen_addresses\s*=.*',
"listen_addresses = '{}'".format(addresses), "listen_addresses = '{}'".format(addresses),
use_sudo=True) use_sudo=True)
restart(c) restart(c)

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2019 Lance Edgar # Copyright © 2010-2023 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -240,6 +240,10 @@ def sed(c, filename, before, after, limit='', use_sudo=False, backup='.bak',
after = after.replace(char, r'\%s' % char) after = after.replace(char, r'\%s' % char)
if limit: if limit:
limit = r'/%s/ ' % limit limit = r'/%s/ ' % limit
# if replacement text contains single quote chars, must escape them
after = after.replace("'", "'\"'\"'")
context = { context = {
'script': r"'%ss/%s/%s/%sg'" % (limit, before, after, flags), 'script': r"'%ss/%s/%s/%sg'" % (limit, before, after, flags),
'filename': _expand_path(c, filename), 'filename': _expand_path(c, filename),