Select Git revision
check_psql.py
Forked from
hub / hub
195 commits behind the upstream repository.

Roang authored
* Use psycopg v3 instead of psycopg2 * Direct import of used fuctions * Fix linting errors
check_psql.py 655 B
#!/usr/bin/env python3
import os
import sys
from psycopg import connect
from psycopg.errors import OperationalError
URL = os.getenv('DATABASE_URL')
if URL is None or URL == '':
print('No DATABASE_URL specified!', file=sys.stderr)
sys.exit(2)
try:
if URL.startswith('postgis://'):
URL = 'postgresql://' + URL[len('postgis://') :]
connect(URL)
except OperationalError as err:
print('ERROR', file=sys.stderr)
print(' ', err, sep='', file=sys.stderr)
sys.exit(1)
except Exception as err: # pylint: disable=W0718
print('UNKNOWN', file=sys.stderr)
print(' ', err, sep='', file=sys.stderr)
sys.exit(3)