mirror of
https://github.com/ZettaIO/restic-compose-backup.git
synced 2025-09-28 06:35:24 +00:00
ping postgres with pg_isready
This commit is contained in:
@@ -10,7 +10,7 @@ def test():
|
||||
|
||||
|
||||
def ping_mysql(host, port, username, password) -> int:
|
||||
"""Check if the database is up and can be reached"""
|
||||
"""Check if the mysql is up and can be reached"""
|
||||
return run([
|
||||
'mysqladmin',
|
||||
'ping',
|
||||
@@ -25,7 +25,7 @@ def ping_mysql(host, port, username, password) -> int:
|
||||
|
||||
|
||||
def ping_mariadb(host, port, username, password) -> int:
|
||||
"""Check if the database is up and can be reached"""
|
||||
"""Check if the mariadb is up and can be reached"""
|
||||
return run([
|
||||
'mysqladmin',
|
||||
'ping',
|
||||
@@ -39,8 +39,14 @@ def ping_mariadb(host, port, username, password) -> int:
|
||||
])
|
||||
|
||||
|
||||
def ping_postgres(self) -> int:
|
||||
return -1
|
||||
def ping_postgres(host, port, username, password) -> int:
|
||||
"""Check if postgres can be reached"""
|
||||
return run([
|
||||
"pg_isready",
|
||||
f"--host={host}",
|
||||
f"--port={port}",
|
||||
f"--username={username}",
|
||||
])
|
||||
|
||||
|
||||
def run(cmd: List[str]) -> int:
|
||||
|
@@ -70,8 +70,13 @@ class PostgresContainer(Container):
|
||||
|
||||
def ping(self) -> bool:
|
||||
"""Check the availability of the service"""
|
||||
# raise NotImplementedError("Base container class don't implement this")
|
||||
print("Implement postgres ping!")
|
||||
creds = self.get_credentials()
|
||||
return commands.ping_postgres(
|
||||
creds['host'],
|
||||
creds['port'],
|
||||
creds['username'],
|
||||
creds['password'],
|
||||
)
|
||||
|
||||
def dump_command(self) -> list:
|
||||
"""list: create a dump command restic and use to send data through stdin"""
|
||||
|
Reference in New Issue
Block a user