OnlineJudge/deploy/entrypoint.sh

64 lines
1.9 KiB
Bash
Raw Normal View History

2017-12-19 14:25:10 +00:00
#!/bin/sh
2017-10-23 02:47:26 +00:00
2017-11-25 04:30:00 +00:00
APP=/app
DATA=/data
2017-10-23 02:47:26 +00:00
2018-05-05 07:21:53 +00:00
mkdir -p $DATA/log $DATA/config $DATA/ssl $DATA/test_case $DATA/public/upload $DATA/public/avatar $DATA/public/website
2017-12-15 05:35:35 +00:00
2018-05-05 07:21:53 +00:00
if [ ! -f "$DATA/config/secret.key" ]; then
echo $(cat /dev/urandom | head -1 | md5sum | head -c 32) > "$DATA/config/secret.key"
2017-10-23 02:47:26 +00:00
fi
2017-12-15 05:35:35 +00: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 02:47:26 +00:00
2017-11-25 04:30:00 +00: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
2017-12-15 17:38:44 +00:00
cd $APP/deploy/nginx
ln -sf locations.conf https_locations.conf
if [ -z "$FORCE_HTTPS" ]; then
ln -sf locations.conf http_locations.conf
else
ln -sf https_redirect.conf http_locations.conf
fi
2018-01-05 01:50:25 +00:00
if [ ! -z "$LOWER_IP_HEADER" ]; then
sed -i "s/__IP_HEADER__/\$http_$LOWER_IP_HEADER/g" api_proxy.conf;
else
sed -i "s/__IP_HEADER__/\$remote_addr/g" api_proxy.conf;
fi
2017-12-27 14:04:06 +00:00
cd $APP/dist
if [ ! -z "$STATIC_CDN_HOST" ]; then
2018-01-06 14:24:55 +00:00
find . -name "*.*" -type f -exec sed -i "s/__STATIC_CDN_HOST__/\/$STATIC_CDN_HOST/g" {} \;
else
2018-01-06 14:24:55 +00:00
find . -name "*.*" -type f -exec sed -i "s/__STATIC_CDN_HOST__\///g" {} \;
2017-12-27 14:04:06 +00:00
fi
2017-11-25 04:30:00 +00:00
cd $APP
2017-10-23 12:59:44 +00:00
n=0
2017-11-24 19:37:40 +00:00
while [ $n -lt 5 ]
2017-10-23 12:59:44 +00:00
do
2017-11-24 19:37:40 +00:00
python manage.py migrate --no-input &&
2017-11-25 04:54:29 +00:00
python manage.py inituser --username=root --password=rootroot --action=create_super_admin &&
2018-01-06 06:26:46 +00:00
echo "from options.options import SysOptions; SysOptions.judge_server_token='$JUDGE_SERVER_TOKEN'" | python manage.py shell &&
2017-11-24 19:37:40 +00:00
break
n=$(($n+1))
echo "Failed to migrate, going to retry..."
sleep 8
2017-10-23 12:59:44 +00:00
done
2017-11-25 04:30:00 +00:00
chown -R nobody:nogroup $DATA $APP/dist
2018-01-06 06:26:46 +00:00
exec supervisord -c /app/deploy/supervisord.conf