Reputation: 11
I am trying to write a script for RHEL8 servers which takes input parameter postgresql version, and it will install a postgresql instance of that version number.
e.g.
db_version = 15.6
db_version_short = 15
I am trying to use python's Subprocess library to install postgresql, but the script is hanging and times-out with errors:
#!/usr/bin/env python3
import sys
import subprocess;
import os
def runcmd(cmd, verbose = True, *args, **kwargs):
process = subprocess.Popen(
cmd,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
shell = True
)
std_out, std_err = process.communicate()
if verbose:
print((std_out.strip()).decode('utf-8'), std_err)
pass
db_version = 15.6
db_version_short = (str(db_version)).split('.')[0]
runcmd('dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm')
#You can verify the PostgreSQL package details with the following command
runcmd('rpm -qi pgdg-redhat-repo')
#If the default PostgreSQL version is enabled in your RHEL8 installation, then disable it by running the following
runcmd('dnf module disable postgresql -y')
runcmd('dnf clean all')
#dnf install
install_cmd = f'dnf -y install postgresql{db_version_short}-server-{db_version}'
runcmd(install_cmd, verbose = True)
The above steps work without issue when I run them manually in my terminal.
But it seems to encounter some issues when I run them from the scipt and the script hangs.
I believe it is hanging on the following line when I run it:
runcmd('dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm')
outputs from last time I ran it:
Updating Subscription Management repositories.
Red Hat Enterprise Linux 8 for x86_64 - AppStre 53 kB/s | 2.8 kB 00:00
Red Hat Enterprise Linux 8 for x86_64 - Supplem 39 kB/s | 2.1 kB 00:00
Red Hat Enterprise Linux 8 for x86_64 - BaseOS 46 kB/s | 2.4 kB 00:00
Red Hat Satellite Tools 6.6 for RHEL 8 x86_64 ( 41 kB/s | 2.1 kB 00:00
[MIRROR] pgdg-redhat-repo-latest.noarch.rpm: Curl error (28): Timeout was reached for https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm [Connection timed out after 30000 milliseconds]
[MIRROR] pgdg-redhat-repo-latest.noarch.rpm: Curl error (28): Timeout was reached for https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm [Connection timed out after 30000 milliseconds]
[MIRROR] pgdg-redhat-repo-latest.noarch.rpm: Curl error (28): Timeout was reached for https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm [Connection timed out after 30000 milliseconds]
pgdg-redhat-repo-latest.noarch.rpm 170 B/s | 15 kB 01:30
Package pgdg-redhat-repo-42.0-45PGDG.noarch is already installed.
Dependencies resolved.
Nothing to do.
The issue is inconsistent, it will install it sometimes and then sometimes it will hang,
It would be great if someone could help identify why I am facing the hanging issue with this, or any tips on best practice for this install
Upvotes: 0
Views: 25