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:
		
							parent
							
								
									f97401009e
								
							
						
					
					
						commit
						303f650a0b
					
				
					 1 changed files with 19 additions and 8 deletions
				
			
		| 
						 | 
					@ -2,7 +2,7 @@
 | 
				
			||||||
################################################################################
 | 
					################################################################################
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
#  Rattail -- Retail Software Framework
 | 
					#  Rattail -- Retail Software Framework
 | 
				
			||||||
#  Copyright © 2010-2021 Lance Edgar
 | 
					#  Copyright © 2010-2022 Lance Edgar
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
#  This file is part of Rattail.
 | 
					#  This file is part of Rattail.
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
| 
						 | 
					@ -26,6 +26,7 @@ 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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -53,8 +54,8 @@ def set_listen_addresses(c, *addresses):
 | 
				
			||||||
    Overwrite the `listen_addresses` config setting in `postgresql.conf`.
 | 
					    Overwrite the `listen_addresses` config setting in `postgresql.conf`.
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    version = get_version(c)
 | 
					    version = get_version(c)
 | 
				
			||||||
    if 12 <= version < 13:
 | 
					    if version > 12:
 | 
				
			||||||
        version = 12
 | 
					        version = int(version)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    addresses = ','.join(addresses)
 | 
					    addresses = ','.join(addresses)
 | 
				
			||||||
    # TODO: this does not seem to work, so cannot do this..?  need to
 | 
					    # 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('*', '\\\\*')
 | 
					    # 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):
 | 
				
			||||||
        uncomment(c, '/etc/postgresql/{}/main/postgresql.conf'.format(version),
 | 
					        uncomment(c, '/etc/postgresql/{}/main/postgresql.conf'.format(version),
 | 
				
			||||||
                  r'^#listen_addresses = .*',
 | 
					                  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 = .*',
 | 
					            r'listen_addresses\s*=.*',
 | 
				
			||||||
            "listen_addresses = '{}'".format(addresses),
 | 
					            "listen_addresses = '{}'".format(addresses),
 | 
				
			||||||
            use_sudo=True)
 | 
					            use_sudo=True)
 | 
				
			||||||
        restart(c)
 | 
					        restart(c)
 | 
				
			||||||
| 
						 | 
					@ -78,8 +89,8 @@ def add_hba_entry(c, entry):
 | 
				
			||||||
    Add an entry to the `pg_hba.conf` file.
 | 
					    Add an entry to the `pg_hba.conf` file.
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    version = get_version(c)
 | 
					    version = get_version(c)
 | 
				
			||||||
    if 12 <= version < 13:
 | 
					    if version > 12:
 | 
				
			||||||
        version = 12
 | 
					        version = int(version)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if not contains(c, '/etc/postgresql/{}/main/pg_hba.conf'.format(version),
 | 
					    if not contains(c, '/etc/postgresql/{}/main/pg_hba.conf'.format(version),
 | 
				
			||||||
                    entry, use_sudo=True):
 | 
					                    entry, use_sudo=True):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue