inital commit 1
This commit is contained in:
commit
db645123c7
196 files changed
+11102
No files matched your search
@@ -0,0 +1,77 @@
|
||||
#!/bin/sh
|
||||
|
||||
APP=/app
|
||||
DATA=/data
|
||||
|
||||
mkdir -p $DATA/log $DATA/config $DATA/ssl $DATA/test_case $DATA/public/upload $DATA/public/avatar $DATA/public/website
|
||||
|
||||
if [ ! -f "$DATA/config/secret.key" ]; then
|
||||
echo $(cat /dev/urandom | head -1 | md5sum | head -c 32) > "$DATA/config/secret.key"
|
||||
fi
|
||||
|
||||
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
|
||||
|
||||
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/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
|
||||
|
||||
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
|
||||
|
||||
if [ -z "$MAX_WORKER_NUM" ]; then
|
||||
export CPU_CORE_NUM=$(grep -c ^processor /proc/cpuinfo)
|
||||
if [[ $CPU_CORE_NUM -lt 2 ]]; then
|
||||
export MAX_WORKER_NUM=2
|
||||
else
|
||||
export MAX_WORKER_NUM=$(($CPU_CORE_NUM))
|
||||
fi
|
||||
fi
|
||||
|
||||
cd $APP/dist
|
||||
if [ ! -z "$STATIC_CDN_HOST" ]; then
|
||||
find . -name "*.*" -type f -exec sed -i "s/__STATIC_CDN_HOST__/\/$STATIC_CDN_HOST/g" {} \;
|
||||
else
|
||||
find . -name "*.*" -type f -exec sed -i "s/__STATIC_CDN_HOST__\///g" {} \;
|
||||
fi
|
||||
|
||||
cd $APP
|
||||
|
||||
n=0
|
||||
while [ $n -lt 5 ]
|
||||
do
|
||||
python manage.py migrate --no-input &&
|
||||
python manage.py inituser --username=root --password=rootroot --action=create_super_admin &&
|
||||
echo "from options.options import SysOptions; SysOptions.judge_server_token='$JUDGE_SERVER_TOKEN'" | python manage.py shell &&
|
||||
echo "from conf.models import JudgeServer; JudgeServer.objects.update(task_number=0)" | python manage.py shell &&
|
||||
break
|
||||
n=$(($n+1))
|
||||
echo "Failed to migrate, going to retry..."
|
||||
sleep 8
|
||||
done
|
||||
|
||||
addgroup -g 903 spj
|
||||
adduser -u 900 -S -G spj server
|
||||
|
||||
chown -R server:spj $DATA $APP/dist
|
||||
find $DATA/test_case -type d -exec chmod 710 {} \;
|
||||
find $DATA/test_case -type f -exec chmod 640 {} \;
|
||||
exec supervisord -c /app/deploy/supervisord.conf
|
||||
@@ -0,0 +1,11 @@
|
||||
import xmlrpc.client
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
with xmlrpc.client.ServerProxy("http://localhost:9005/RPC2") as server:
|
||||
info = server.supervisor.getAllProcessInfo()
|
||||
error_states = list(filter(lambda x: x["state"] != 20, info))
|
||||
exit(len(error_states))
|
||||
except Exception as e:
|
||||
print(e.with_traceback())
|
||||
exit(1)
|
||||
@@ -0,0 +1,6 @@
|
||||
proxy_pass http://backend;
|
||||
proxy_set_header X-Real-IP __IP_HEADER__;
|
||||
proxy_set_header Host $http_host;
|
||||
client_max_body_size 200M;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Connection '';
|
||||
@@ -0,0 +1,7 @@
|
||||
location /api/judge_server_heartbeat {
|
||||
include api_proxy.conf;
|
||||
}
|
||||
|
||||
location / {
|
||||
return 301 https://$host$request_uri;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
location /public {
|
||||
root /data;
|
||||
}
|
||||
|
||||
location /api {
|
||||
include api_proxy.conf;
|
||||
}
|
||||
|
||||
location /admin {
|
||||
root /app/dist/admin;
|
||||
try_files $uri $uri/ /index.html =404;
|
||||
}
|
||||
|
||||
location /.well-known {
|
||||
alias /data/ssl/.well-known;
|
||||
}
|
||||
|
||||
location / {
|
||||
root /app/dist;
|
||||
try_files $uri $uri/ /index.html =404;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
user nginx;
|
||||
daemon off;
|
||||
pid /tmp/nginx.pid;
|
||||
worker_processes auto;
|
||||
pcre_jit on;
|
||||
error_log /data/log/nginx_error.log warn;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
server_tokens off;
|
||||
keepalive_timeout 65;
|
||||
sendfile on;
|
||||
tcp_nodelay on;
|
||||
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_types application/javascript text/css;
|
||||
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" '
|
||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
access_log /data/log/nginx_access.log main;
|
||||
|
||||
upstream backend {
|
||||
server 127.0.0.1:8080;
|
||||
keepalive 32;
|
||||
}
|
||||
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
add_header X-Frame-Options SAMEORIGIN always;
|
||||
add_header X-Content-Type-Options nosniff always;
|
||||
|
||||
server {
|
||||
listen 8000 default_server;
|
||||
server_name _;
|
||||
|
||||
include http_locations.conf;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 1443 ssl http2 default_server;
|
||||
server_name _;
|
||||
ssl_certificate /data/ssl/server.crt;
|
||||
ssl_certificate_key /data/ssl/server.key;
|
||||
ssl_protocols TLSv1.2;
|
||||
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
|
||||
ssl_prefer_server_ciphers on;
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
|
||||
include https_locations.conf;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
coverage==7.4.1
|
||||
django-cas-ng==5.0.1
|
||||
django-dbconn-retry==0.1.9
|
||||
django-dramatiq==0.12.0
|
||||
django-redis==5.4.0
|
||||
Django==5.0.11
|
||||
djangorestframework==3.15.2
|
||||
dramatiq==1.16.0
|
||||
entrypoints==0.4
|
||||
Envelopes==0.4
|
||||
flake8-coding==1.3.2
|
||||
flake8-quotes==3.4.0
|
||||
flake8==7.0.0
|
||||
gunicorn==22.0.0
|
||||
jsonfield==3.1.0
|
||||
otpauth==1.0.1
|
||||
pillow==11.0.0
|
||||
psycopg2==2.9.10
|
||||
python-dateutil==2.9.0
|
||||
qrcode==8.0
|
||||
sentry-sdk==2.19.2
|
||||
XlsxWriter==3.2.0
|
||||
@@ -0,0 +1,51 @@
|
||||
[supervisord]
|
||||
logfile=/data/log/supervisord.log
|
||||
logfile_maxbytes=10MB
|
||||
logfile_backups=10
|
||||
loglevel=info
|
||||
pidfile=/tmp/supervisord.pid
|
||||
nodaemon=true
|
||||
childlogdir=/data/log/
|
||||
|
||||
[inet_http_server]
|
||||
port=127.0.0.1:9005
|
||||
|
||||
[rpcinterface:supervisor]
|
||||
supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface
|
||||
|
||||
[supervisorctl]
|
||||
serverurl=http://127.0.0.1:9005
|
||||
|
||||
[program:nginx]
|
||||
command=nginx -c /app/deploy/nginx/nginx.conf
|
||||
directory=/app/
|
||||
stdout_logfile=/data/log/nginx.log
|
||||
stderr_logfile=/data/log/nginx.log
|
||||
autostart=true
|
||||
autorestart=true
|
||||
startsecs=5
|
||||
stopwaitsecs = 5
|
||||
killasgroup=true
|
||||
|
||||
[program:gunicorn]
|
||||
command=gunicorn oj.wsgi --user server --group spj --bind 127.0.0.1:8080 --workers %(ENV_MAX_WORKER_NUM)s --threads 4 --max-requests-jitter 10000 --max-requests 1000000 --keep-alive 32
|
||||
directory=/app/
|
||||
stdout_logfile=/data/log/gunicorn.log
|
||||
stderr_logfile=/data/log/gunicorn.log
|
||||
autostart=true
|
||||
autorestart=true
|
||||
startsecs=5
|
||||
stopwaitsecs = 5
|
||||
killasgroup=true
|
||||
|
||||
[program:dramatiq]
|
||||
command=python3 manage.py rundramatiq --processes %(ENV_MAX_WORKER_NUM)s --threads 4
|
||||
directory=/app/
|
||||
user=nobody
|
||||
stdout_logfile=/data/log/dramatiq.log
|
||||
stderr_logfile=/data/log/dramatiq.log
|
||||
autostart=true
|
||||
autorestart=true
|
||||
startsecs=5
|
||||
stopwaitsecs = 5
|
||||
killasgroup=true
|
||||
@@ -0,0 +1,8 @@
|
||||
FROM alpine:3.6
|
||||
|
||||
RUN apk add --update --no-cache rsync
|
||||
|
||||
ADD ./run.sh /tmp/run.sh
|
||||
ADD ./rsyncd.conf /etc/rsyncd.conf
|
||||
|
||||
CMD /bin/sh /tmp/run.sh
|
||||
@@ -0,0 +1,12 @@
|
||||
port = 873
|
||||
uid = root
|
||||
gid = root
|
||||
use chroot = yes
|
||||
read only = yes
|
||||
log file = /log/rsyncd.log
|
||||
|
||||
[testcase]
|
||||
path = /test_case/
|
||||
list = yes
|
||||
auth users = ojrsync
|
||||
secrets file = /etc/rsyncd.passwd
|
||||
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
slave_runner()
|
||||
{
|
||||
while true
|
||||
do
|
||||
rsync -avzP --delete --progress --password-file=/etc/rsync_slave.passwd $RSYNC_USER@$RSYNC_MASTER_ADDR::testcase /test_case >> /log/rsync_slave.log
|
||||
sleep 5
|
||||
done
|
||||
}
|
||||
|
||||
master_runner()
|
||||
{
|
||||
rsync --daemon --config=/etc/rsyncd.conf
|
||||
while true
|
||||
do
|
||||
sleep 60
|
||||
done
|
||||
}
|
||||
|
||||
if [ "$RSYNC_MODE" = "master" ]; then
|
||||
if [ ! -f "/etc/rsyncd.passwd" ]; then
|
||||
echo "$RSYNC_USER:$RSYNC_PASSWORD" > /etc/rsyncd.passwd
|
||||
fi
|
||||
chmod 600 /etc/rsyncd.passwd
|
||||
master_runner
|
||||
else
|
||||
if [ ! -f "/etc/rsync_slave.passwd" ]; then
|
||||
echo "$RSYNC_PASSWORD" > /etc/rsync_slave.passwd
|
||||
fi
|
||||
chmod 600 /etc/rsync_slave.passwd
|
||||
slave_runner
|
||||
fi
|
||||
Reference in new issue
Block a user