2017-10-23 10:47:26 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-11-25 12:30:00 +08:00
|
|
|
APP=/app
|
|
|
|
DATA=/data
|
2017-10-23 10:47:26 +08:00
|
|
|
|
2017-12-15 13:35:35 +08:00
|
|
|
mkdir -p $DATA/log $DATA/ssl $DATA/test_case $DATA/public/upload $DATA/public/avatar $DATA/public/website
|
|
|
|
|
2017-11-25 12:30:00 +08:00
|
|
|
if [ ! -f "$APP/oj/custom_settings.py" ]; then
|
|
|
|
echo SECRET_KEY=\"$(cat /dev/urandom | head -1 | md5sum | head -c 32)\" >> $APP/oj/custom_settings.py
|
2017-10-23 10:47:26 +08:00
|
|
|
fi
|
|
|
|
|
2017-12-15 13:35:35 +08:00
|
|
|
if [ ! -f "$DATA/public/avatar/default.png" ]; then
|
|
|
|
cp data/public/avatar/default.png $DATA/public/avatar
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f "$DATA/public/website/favicon.ico" ]; then
|
|
|
|
cp data/public/website/favicon.ico $DATA/public/website
|
|
|
|
fi
|
2017-10-23 10:47:26 +08:00
|
|
|
|
2017-11-25 12:30:00 +08:00
|
|
|
SSL="$DATA/ssl"
|
|
|
|
if [ ! -f "$SSL/server.key" ]; then
|
|
|
|
openssl req -x509 -newkey rsa:2048 -keyout "$SSL/server.key" -out "$SSL/server.crt" -days 1000 \
|
|
|
|
-subj "/C=CN/ST=Beijing/L=Beijing/O=Beijing OnlineJudge Technology Co., Ltd./OU=Service Infrastructure Department/CN=`hostname`" -nodes
|
|
|
|
fi
|
|
|
|
|
|
|
|
cd $APP
|
2017-10-23 20:59:44 +08:00
|
|
|
|
|
|
|
n=0
|
2017-11-25 03:37:40 +08:00
|
|
|
while [ $n -lt 5 ]
|
2017-10-23 20:59:44 +08:00
|
|
|
do
|
2017-11-25 03:37:40 +08:00
|
|
|
python manage.py migrate --no-input &&
|
2017-11-25 12:54:29 +08:00
|
|
|
python manage.py inituser --username=root --password=rootroot --action=create_super_admin &&
|
2017-11-25 03:37:40 +08:00
|
|
|
break
|
|
|
|
n=$(($n+1))
|
|
|
|
echo "Failed to migrate, going to retry..."
|
|
|
|
sleep 8
|
2017-10-23 20:59:44 +08:00
|
|
|
done
|
|
|
|
|
2017-12-01 11:13:23 +08:00
|
|
|
echo "from options.options import SysOptions; SysOptions.judge_server_token='$JUDGE_SERVER_TOKEN'" | python manage.py shell || exit 1
|
2017-11-30 10:14:51 +08:00
|
|
|
|
2017-11-25 12:30:00 +08:00
|
|
|
chown -R nobody:nogroup $DATA $APP/dist
|
2017-12-15 13:35:35 +08:00
|
|
|
exec supervisord -c /app/deploy/supervisord.conf
|