-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathstart-servers.sh
100 lines (94 loc) · 3.3 KB
/
start-servers.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
set -e
function waitForPort {
started=false
echo -n "waiting for port "$1" "
for i in `seq 0 29`; do
echo -n "."
if [ $(curl -I "http://localhost:"$1 2>/dev/null | grep "HTTP/1" | cut -d' ' -f2)"" == "404" ]; then
started=true
break
fi
sleep 1
done
echo ""
if [ ${started} != true ]; then
echo "server on port "$1" did not start"
exit -1
fi
}
DIRHASH=$(pwd | shasum | cut -d" " -f1 | cut -c1-6)
# qabel-drop
echo -e "\n### STARTING DROP SERVER"
cd qabel-drop
if [ -f drop.pid ]; then
echo -n "stopping old drop instance... "
(cat drop.pid | xargs kill && echo "done") || echo "already gone"
fi
DROP_VENV="venv_"${DIRHASH}
if [ ! -d ${DROP_VENV} ]; then
virtualenv --no-site-packages --python=python3.5 ${DROP_VENV}
fi
source "${DROP_VENV}/bin/activate"
echo "installing dependencies..."
pip install -q -U pip
pip install -q -r requirements.txt
if [ ! -d config.py ]; then
cp drop_server/config.py.example drop_server/config.py
fi
python manage.py create_db
python manage.py runserver --host 0.0.0.0 --port 5000 > drop.log 2>&1 &
echo $! > drop.pid
deactivate
cd ..
waitForPort 5000
echo -e "\n### STARTING ACCOUNTING SERVER"
# qabel-accounting
cd qabel-accounting
ACCOUNTING_VENV="venv_"${DIRHASH}
if [ -f accounting.pid ]; then
echo "stopping old accounting instance"
cat accounting.pid | xargs kill || echo "already gone"
fi
if [ ! -d ${ACCOUNTING_VENV} ]; then
virtualenv --no-site-packages --always-copy --python=python3.5 ${ACCOUNTING_VENV}
fi
source "${ACCOUNTING_VENV}/bin/activate"
echo "installing dependencies..."
pip install -q -U pip
pip install -q -r requirements.txt
yes "yes" | python manage.py migrate
cp qabel_id/settings/local_settings.example.py qabel_id/settings/local_settings.py
echo -e "\nEMAIL_BACKEND = 'django.core.mail.backends.dummy.EmailBackend'\n" >> qabel_id/settings/local_settings.py
echo -e "\nSECRET_KEY = '=tmcici-p92_^_jih9ud11#+wb7*i21firlrtcqh\$p+d7o*49@'\n" >> qabel_id/settings/local_settings.py
DJANGO_SETTINGS_MODULE=qabel_id.settings.production_settings python manage.py testserver testdata.json --addrport 0.0.0.0:9696 > accounting.log 2>&1 &
echo $! > accounting.pid
deactivate
cd ..
waitForPort 9696
echo -e "\n### STARTING BLOCK SERVER"
# qabel-block
cd qabel-block
BLOCK_VENV="venv_"${DIRHASH}
if [ -f block.pid ]; then
echo "stopping old block instance"
cat block.pid | xargs kill || echo "already gone"
fi
if [ ! -d ${BLOCK_VENV} ]; then
virtualenv --no-site-packages --always-copy --python=python3.5 ${BLOCK_VENV}
fi
cp config.ini.example config.ini
sed --in-place 's/api_secret=".*"/api_secret="Changeme"/g' config.ini
echo -e "\npsql_dsn='postgres://block_dummy:qabel_test_dummy@localhost/block_dummy'" >> config.ini
source ${BLOCK_VENV}"/bin/activate"
echo "installing dependencies..."
pip install -q -U pip
pip install -q -r requirements.txt
cd src
echo "preparing database..."
alembic -x 'url=postgres://block_dummy:qabel_test_dummy@localhost/block_dummy' upgrade head
python run.py --debug --dummy --dummy-log --dummy-cache --apisecret=Changeme --accounting-host=http://localhost:9696 --address=0.0.0.0 --port=9697 --psql-dsn='postgres://block_dummy:qabel_test_dummy@localhost/block_dummy' > ../block.log 2>&1 &
echo $! > ../block.pid
deactivate
cd ../..
waitForPort 9697