From e4648cf47dd94276bad84f6227c184efa38dc116 Mon Sep 17 00:00:00 2001 From: spxcds Date: Wed, 11 May 2016 13:01:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0rsync=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + dockerfiles/test_case_rsync/Dockerfile | 3 +++ .../docker-compose.example.yml | 19 +++++++++++++++++++ dockerfiles/test_case_rsync/rsyncd.conf | 11 +++++++++++ .../test_case_rsync/rsyncd.example.passwd | 1 + dockerfiles/test_case_rsync/rsyncd_slave.sh | 6 ++++++ dockerfiles/test_case_rsync/run.sh | 16 ++++++++++++++++ 7 files changed, 57 insertions(+) create mode 100644 dockerfiles/test_case_rsync/Dockerfile create mode 100644 dockerfiles/test_case_rsync/docker-compose.example.yml create mode 100644 dockerfiles/test_case_rsync/rsyncd.conf create mode 100644 dockerfiles/test_case_rsync/rsyncd.example.passwd create mode 100644 dockerfiles/test_case_rsync/rsyncd_slave.sh create mode 100644 dockerfiles/test_case_rsync/run.sh diff --git a/.gitignore b/.gitignore index 9cb7a002..1270921e 100644 --- a/.gitignore +++ b/.gitignore @@ -67,3 +67,4 @@ upload/ custom_settings.py docker-compose.yml *.zip +rsyncd.passwd \ No newline at end of file diff --git a/dockerfiles/test_case_rsync/Dockerfile b/dockerfiles/test_case_rsync/Dockerfile new file mode 100644 index 00000000..85dc054a --- /dev/null +++ b/dockerfiles/test_case_rsync/Dockerfile @@ -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 diff --git a/dockerfiles/test_case_rsync/docker-compose.example.yml b/dockerfiles/test_case_rsync/docker-compose.example.yml new file mode 100644 index 00000000..13857fbe --- /dev/null +++ b/dockerfiles/test_case_rsync/docker-compose.example.yml @@ -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} diff --git a/dockerfiles/test_case_rsync/rsyncd.conf b/dockerfiles/test_case_rsync/rsyncd.conf new file mode 100644 index 00000000..52e7a557 --- /dev/null +++ b/dockerfiles/test_case_rsync/rsyncd.conf @@ -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 diff --git a/dockerfiles/test_case_rsync/rsyncd.example.passwd b/dockerfiles/test_case_rsync/rsyncd.example.passwd new file mode 100644 index 00000000..54329f0e --- /dev/null +++ b/dockerfiles/test_case_rsync/rsyncd.example.passwd @@ -0,0 +1 @@ +YOUR_PASSWORD diff --git a/dockerfiles/test_case_rsync/rsyncd_slave.sh b/dockerfiles/test_case_rsync/rsyncd_slave.sh new file mode 100644 index 00000000..e63e1128 --- /dev/null +++ b/dockerfiles/test_case_rsync/rsyncd_slave.sh @@ -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 diff --git a/dockerfiles/test_case_rsync/run.sh b/dockerfiles/test_case_rsync/run.sh new file mode 100644 index 00000000..7ac3e0b5 --- /dev/null +++ b/dockerfiles/test_case_rsync/run.sh @@ -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