-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.sh
executable file
·44 lines (32 loc) · 938 Bytes
/
start.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env bash
# Start-up script that waits for Postgres to be ready
# Christopher Harrison <[email protected]>
set -eu
wait_for_postgres() {
local -i max_attempts="$1"
python -u <<-PYTHON
import os
from time import sleep
from cogs import config, mail
from cogs.db.interface import Database
config_file = os.getenv("COGS_CONFIG", "config.yaml")
c = config.load(config_file)
available = False
attempts = 0
while not available and attempts < ${max_attempts}:
try:
db = Database(c["database"])
available = True
except:
sleep_for = 2 ** attempts
print(f"Database is not ready yet! Will try again in {sleep_for} seconds...")
sleep(sleep_for)
attempts += 1
if not available:
print("Could not connect to the database!")
exit(1)
PYTHON
}
MAX_ATTEMPTS="${MAX_ATTEMPTS-5}"
wait_for_postgres "${MAX_ATTEMPTS}" >&2
exec python "$@" -m cogs.main