mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	installer: Add run_psql_as_postgres function zulip_tools.py.
Add a helper `run_psql_as_postgres` function in `scripts/lib/zulip_tools.py`. This is preparatory refactoring for the work to add custom database and user names.
This commit is contained in:
		@@ -32,6 +32,7 @@ from scripts.lib.zulip_tools import (
 | 
				
			|||||||
    get_config_file,
 | 
					    get_config_file,
 | 
				
			||||||
    get_tornado_ports,
 | 
					    get_tornado_ports,
 | 
				
			||||||
    parse_os_release,
 | 
					    parse_os_release,
 | 
				
			||||||
 | 
					    run_psql_as_postgres,
 | 
				
			||||||
    su_to_zulip,
 | 
					    su_to_zulip,
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -137,13 +138,8 @@ if os.path.exists("/etc/init.d/postgresql"):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
if glob.glob("/usr/share/postgresql/*/extension/tsearch_extras.control"):
 | 
					if glob.glob("/usr/share/postgresql/*/extension/tsearch_extras.control"):
 | 
				
			||||||
    # Remove legacy tsearch_extras package references
 | 
					    # Remove legacy tsearch_extras package references
 | 
				
			||||||
    subprocess.check_call(
 | 
					    run_psql_as_postgres(
 | 
				
			||||||
        [
 | 
					        sql_query="DROP EXTENSION IF EXISTS tsearch_extras;",
 | 
				
			||||||
            "su",
 | 
					 | 
				
			||||||
            "postgres",
 | 
					 | 
				
			||||||
            "-c",
 | 
					 | 
				
			||||||
            'psql -v ON_ERROR_STOP=1 zulip -c "DROP EXTENSION IF EXISTS tsearch_extras;"',
 | 
					 | 
				
			||||||
        ]
 | 
					 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    subprocess.check_call(["apt-get", "remove", "-y", "postgresql-*-tsearch-extras"])
 | 
					    subprocess.check_call(["apt-get", "remove", "-y", "postgresql-*-tsearch-extras"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -580,6 +580,26 @@ def get_deploy_options(config_file: configparser.RawConfigParser) -> List[str]:
 | 
				
			|||||||
    return get_config(config_file, "deployment", "deploy_options", "").strip().split()
 | 
					    return get_config(config_file, "deployment", "deploy_options", "").strip().split()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def run_psql_as_postgres(
 | 
				
			||||||
 | 
					    sql_query: str,
 | 
				
			||||||
 | 
					) -> None:
 | 
				
			||||||
 | 
					    subcmd = " ".join(
 | 
				
			||||||
 | 
					        map(
 | 
				
			||||||
 | 
					            shlex.quote,
 | 
				
			||||||
 | 
					            [
 | 
				
			||||||
 | 
					                "psql",
 | 
				
			||||||
 | 
					                "-v",
 | 
				
			||||||
 | 
					                "ON_ERROR_STOP=1",
 | 
				
			||||||
 | 
					                # TODO: Stop hardcoding the database name.
 | 
				
			||||||
 | 
					                "zulip",
 | 
				
			||||||
 | 
					                "-c",
 | 
				
			||||||
 | 
					                sql_query,
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    subprocess.check_call(["su", "postgres", "-c", subcmd])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_tornado_ports(config_file: configparser.RawConfigParser) -> List[int]:
 | 
					def get_tornado_ports(config_file: configparser.RawConfigParser) -> List[int]:
 | 
				
			||||||
    ports = []
 | 
					    ports = []
 | 
				
			||||||
    if config_file.has_section("tornado_sharding"):
 | 
					    if config_file.has_section("tornado_sharding"):
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user