最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Postgresql dnf install issues when running from python subprocess script - Stack Overflow

matteradmin1PV0评论

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 = processmunicate()
    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 .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 .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 .noarch.rpm [Connection timed out after 30000 milliseconds]
[MIRROR] pgdg-redhat-repo-latest.noarch.rpm: Curl error (28): Timeout was reached for .noarch.rpm [Connection timed out after 30000 milliseconds]
[MIRROR] pgdg-redhat-repo-latest.noarch.rpm: Curl error (28): Timeout was reached for .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

Post a comment

comment list (0)

  1. No comments so far