forked from mkrelle/lemur-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api-start.sh
executable file
·45 lines (37 loc) · 1.49 KB
/
api-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
45
#!/bin/bash
# sleep for $SLEEP seconds to a maxium of 10 tries
SLEEP=1
db_not_ready() {
echo ERROR: failed to connect to db
echo " "
echo "postgresql server was not initialised in time or correctly. Try running 'docker-compose up' again."
echo If the problem persists, consider inspecting the postgresql container for logs or waiting longer for
echo DB to initialise by increasing the SLEEP var in web/api-start.sh to a higher value and rebuilding
echo the containers
echo " "
exit 1
}
wait_db() {
for i in $(seq 1 10); do
echo -e "\033[1mAttempt to connect to db.. try #$i\033[0m"
sudo -u postgres psql -h postgres --command 'select 1;' && return 0
sleep $SLEEP
done
return 1
}
echo "Waiting for db to become available"
wait_db
[ "x$?" == "x0" ] && printf "db ready!\n\n" || db_not_ready
echo "Creating lemurdb..."
sudo -u postgres psql -h postgres --command "CREATE DATABASE lemur;"
echo "Creating the lemur user..."
sudo -u postgres psql -h postgres --command "CREATE USER lemur WITH SUPERUSER PASSWORD 'lemur';"
echo "Changing postgres password..."
sudo -u postgres psql -h postgres --command "GRANT ALL PRIVILEGES ON DATABASE lemur to lemur;"
echo "Done changing postgres password..."
sudo -u postgres psql -h postgres --command "ALTER ROLE lemur SUPERUSER;"
echo "DONE CREATING lemurdb..."
cd /usr/local/src/lemur/lemur
export PATH=/usr/local/src/lemur/venv/bin:${PATH}
python manage.py init -p password
python manage.py start -w 6 -b 0.0.0.0:8000