OnlineJudge/deploy/run.sh

41 lines
709 B
Bash
Raw Normal View History

2017-10-23 02:47:26 +00:00
#!/bin/bash
BASE=/app
if [ ! -f "$BASE/custom_settings.py" ]; then
echo SECRET_KEY=\"$(cat /dev/urandom | head -1 | md5sum | head -c 32)\" >> /app/oj/custom_settings.py
fi
if [ ! -d "$BASE/log" ]; then
mkdir -p $BASE/log
fi
cd $BASE
find . -name "*.pyc" -delete
2017-10-23 12:59:44 +00:00
chown -R nobody:nogroup $BASE/log
2017-10-23 02:47:26 +00:00
2017-10-23 12:59:44 +00:00
# wait for postgresql start
sleep 5
n=0
while [ $n -lt 3 ]
do
2017-10-23 02:47:26 +00:00
python manage.py migrate
if [ $? -ne 0 ]; then
2017-10-23 12:59:44 +00:00
echo "Can't start server, try again in 3 seconds.."
sleep 3
let "n+=1"
continue
2017-10-23 02:47:26 +00:00
fi
python manage.py initadmin
2017-10-23 12:59:44 +00:00
break
done
if [ $n -eq 3 ]; then
echo "Can't start server, please check log file for details."
exit 1
fi
exec supervisord -c /app/deploy/supervisor.conf