mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-11-04 14:49:58 +08:00
Accept Merge Request #390 创建rsync同步脚本 : (dev -> master)
Merge Request: 创建rsync同步脚本 Created By: @virusdefender Accepted By: @virusdefender URL: https://coding.net/u/virusdefender/p/qduoj/git/merge/390
This commit is contained in:
commit
0f7c853783
1
.gitignore
vendored
1
.gitignore
vendored
@ -67,3 +67,4 @@ upload/
|
|||||||
custom_settings.py
|
custom_settings.py
|
||||||
docker-compose.yml
|
docker-compose.yml
|
||||||
*.zip
|
*.zip
|
||||||
|
rsyncd.passwd
|
||||||
3
dockerfiles/test_case_rsync/Dockerfile
Normal file
3
dockerfiles/test_case_rsync/Dockerfile
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
FROM ubuntu:14.04
|
||||||
|
RUN apt-get update && apt-get -y install rsync
|
||||||
|
CMD /bin/bash /OnlineJudge/dockerfiles/test_case_rsync/run.sh
|
||||||
19
dockerfiles/test_case_rsync/docker-compose.example.yml
Normal file
19
dockerfiles/test_case_rsync/docker-compose.example.yml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
oj_rsync_master:
|
||||||
|
image: oj_rsync
|
||||||
|
volumes:
|
||||||
|
- /home/OnlineJudge:/OnlineJudge
|
||||||
|
- /home/test_case:/OnlineJudge/test_case
|
||||||
|
- /home/log:/OnlineJudge/log
|
||||||
|
ports:
|
||||||
|
- "0.0.0.0:873:873"
|
||||||
|
environment:
|
||||||
|
- RSYNC_MODE=master
|
||||||
|
oj_rsync_slave:
|
||||||
|
image: oj_rsync
|
||||||
|
volumes:
|
||||||
|
- /home/OnlineJudge:/OnlineJudge
|
||||||
|
- /home/test_case:/OnlineJudge/test_case
|
||||||
|
- /home/log:/OnlineJudge/log
|
||||||
|
environment:
|
||||||
|
- RSYNC_MODE=slave
|
||||||
|
- RSYNC_MASTER_ADDR={YOUR_MASTER_ADDR}
|
||||||
11
dockerfiles/test_case_rsync/rsyncd.conf
Normal file
11
dockerfiles/test_case_rsync/rsyncd.conf
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
port = 873
|
||||||
|
uid = root
|
||||||
|
gid = root
|
||||||
|
use chroot = yes
|
||||||
|
read only = yes
|
||||||
|
log file = /OnlineJudge/log/rsyncd.log
|
||||||
|
[testcase]
|
||||||
|
path = /OnlineJudge/test_case/
|
||||||
|
list = yes
|
||||||
|
auth users = ojrsync
|
||||||
|
secrets file = /etc/rsyncd/rsyncd.passwd
|
||||||
1
dockerfiles/test_case_rsync/rsyncd.example.passwd
Normal file
1
dockerfiles/test_case_rsync/rsyncd.example.passwd
Normal file
@ -0,0 +1 @@
|
|||||||
|
YOUR_PASSWORD
|
||||||
6
dockerfiles/test_case_rsync/rsyncd_slave.sh
Normal file
6
dockerfiles/test_case_rsync/rsyncd_slave.sh
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
rsync -avz --delete --progress --password-file=/OnlineJudge/dockerfiles/test_case_rsync/rsyncd.passwd ojrsync@$RSYNC_MASTER_ADDR::testcase /OnlineJudge/test_case >> /OnlineJudge/log/rsync_slave.log
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
16
dockerfiles/test_case_rsync/run.sh
Normal file
16
dockerfiles/test_case_rsync/run.sh
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
if [ "$RSYNC_MODE" = "master" ]; then
|
||||||
|
if [ ! -f "/etc/rsyncd/rsync_master.passwd" ]; then
|
||||||
|
mkdir /etc/rsyncd
|
||||||
|
(echo "ojrsync:" && cat /OnlineJudge/dockerfiles/test_case_rsync/rsyncd.passwd) | tr -d "\n" > /etc/rsyncd/rsyncd.passwd
|
||||||
|
fi
|
||||||
|
chmod 600 /etc/rsyncd/rsyncd.passwd
|
||||||
|
rsync --daemon --config=/OnlineJudge/dockerfiles/test_case_rsync/rsyncd.conf
|
||||||
|
else
|
||||||
|
chmod 600 /OnlineJudge/dockerfiles/test_case_rsync/rsyncd.passwd
|
||||||
|
/bin/bash /OnlineJudge/dockerfiles/test_case_rsync/rsyncd_slave.sh
|
||||||
|
fi
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
sleep 100
|
||||||
|
done
|
||||||
@ -2,11 +2,9 @@
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import MySQLdb
|
import MySQLdb
|
||||||
|
|
||||||
"""
|
"""
|
||||||
docker-compose启动的时候是并行启动的,可能执行本脚本的时候MySQL还没启动完
|
docker-compose启动的时候是并行启动的,可能执行本脚本的时候MySQL还没启动完
|
||||||
"""
|
"""
|
||||||
|
|
||||||
i = 3
|
i = 3
|
||||||
while i:
|
while i:
|
||||||
try:
|
try:
|
||||||
@ -21,6 +19,5 @@ while i:
|
|||||||
print "Failed to create database, error: " + str(e) + ", will retry in 3 seconds"
|
print "Failed to create database, error: " + str(e) + ", will retry in 3 seconds"
|
||||||
i -= 1
|
i -= 1
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
|
||||||
print "Failed to create database"
|
print "Failed to create database"
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|||||||
21
utils/management/commands/initinstall.py
Normal file
21
utils/management/commands/initinstall.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# coding=utf-8
|
||||||
|
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
try:
|
||||||
|
if os.system("python manage.py migrate") != 0:
|
||||||
|
self.stdout.write(self.style.ERROR("Failed to execute command 'migrate'"))
|
||||||
|
exit(1)
|
||||||
|
if os.system("python manage.py migrate --database=submission") != 0:
|
||||||
|
self.stdout.write(self.style.ERROR("Failed to execute command 'migrate --database=submission'"))
|
||||||
|
exit(1)
|
||||||
|
if os.system("python manage.py initadmin") != 0:
|
||||||
|
self.stdout.write(self.style.ERROR("Failed to execute command 'initadmin'"))
|
||||||
|
exit(1)
|
||||||
|
self.stdout.write(self.style.SUCCESS("Done"))
|
||||||
|
except Exception as e:
|
||||||
|
self.stdout.write(self.style.ERROR("Failed to initialize, error: " + str(e)))
|
||||||
Loading…
Reference in New Issue
Block a user