ffe62bdd52
As the wait-for-it script is started before the parsing of the command line, it is always started. It can be a problem if a user wants to start some other binary than odoo (for example a shell). Also, the wait-for-it script is only checking if a port is open on a host and then waits 5 seconds before starting Odoo. With this commit, the wait-for-it script is replaced by a more useful custom python script that checks if the postgresql server is able to handle a connection with the given parameters. Odoo then starts whenever it's ready or fails after a 30 sec timeout.
33 lines
991 B
Python
Executable File
33 lines
991 B
Python
Executable File
#!/usr/bin/env python3
|
|
import argparse
|
|
import psycopg2
|
|
import sys
|
|
import time
|
|
|
|
|
|
if __name__ == '__main__':
|
|
arg_parser = argparse.ArgumentParser()
|
|
arg_parser.add_argument('--db_host', required=True)
|
|
arg_parser.add_argument('--db_port', required=True)
|
|
arg_parser.add_argument('--db_user', required=True)
|
|
arg_parser.add_argument('--db_password', required=True)
|
|
arg_parser.add_argument('--timeout', type=int, default=5)
|
|
|
|
args = arg_parser.parse_args()
|
|
|
|
start_time = time.time()
|
|
while (time.time() - start_time) < args.timeout:
|
|
try:
|
|
conn = psycopg2.connect(user=args.db_user, host=args.db_host, port=args.db_port, password=args.db_password, dbname='postgres')
|
|
error = ''
|
|
break
|
|
except psycopg2.OperationalError as e:
|
|
error = e
|
|
else:
|
|
conn.close()
|
|
time.sleep(1)
|
|
|
|
if error:
|
|
print("Database connection failure: %s" % error, file=sys.stderr)
|
|
sys.exit(1)
|