This commit is contained in:
2022-04-18 11:21:20 +08:00
commit 45a7af638f
210 changed files with 8997 additions and 0 deletions

60
rsync/ADD/ccmd Executable file
View File

@@ -0,0 +1,60 @@
#!/bin/bash
##################################################
# Mount file #
# - /etc/rsyncd.conf #
# Mount dir #
# - LOG_DIR #
# - PATH specified in every module #
##################################################
set -euo pipefail
export LANG=en_US.UTF-8
trap Quit EXIT
PIDS=
GOT_SIGTERM=
LOG_DIR='/var/log/rsync'
function Print {
local file=/dev/null
[ '-f' = "$1" ] && file=$2 && shift && shift
date +"[%F %T] $*" | tee -a $file
}
function Quit {
Print killing rsync ...
while :; do
pkill -f rsync && Print killing rsync ... || break
sleep 1
done
Print Container stopped.
test -n "$GOT_SIGTERM"
}
function StartProc {
Print Start rsync ...
rm -f /var/run/rsyncd.pid
rsync --daemon \
--no-detach \
--port=873 \
--log-file=$LOG_DIR/rsyncd.log \
--dparam=pidfile=/var/run/rsyncd.pid \
&>> $LOG_DIR/rsyncd.out &
PIDS="$PIDS $!"
}
function Main {
local pid=
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done
done
}
# Start here
Main

View File

@@ -0,0 +1,16 @@
# 部署 rsync
- 分享服务器 /data1 和 /data2 目录
- 根据实际环境修改
- docker-compose.yml
- 创建目录
```
grep '\<source:' docker-compose.yml | cut -d: -f2 | xargs mkdir -p
```
- 启动
```
docker-compose up -d
```

View File

@@ -0,0 +1,24 @@
version: "3.7"
services:
rsync:
image: harbor.colben.cn/general/rsync
container_name: rsync
restart: "on-failure"
stop_grace_period: 1m
ports:
- 873:873
volumes:
- type: bind
source: ./rsync/rsyncd.conf
target: /etc/rsyncd.conf
- type: bind
source: ./rsync/log
target: /var/log/rsync
- type: bind
source: /data1
target: /d1
- type: bind
source: /data2
target: /d2

View File

@@ -0,0 +1,15 @@
uid = root
gid = root
use chroot = yes
read only = yes
[data1]
path = /d1/
uid = nobody
gid = nobody
read only = no
use chroot = no
[data2]
path = /d2/

10
rsync/Dockerfile Normal file
View File

@@ -0,0 +1,10 @@
ARG ARCH
FROM harbor.colben.cn/general/alpine$ARCH
MAINTAINER Colben colbenlee@gmail.com
ADD --chown=root:root /ADD/ /opt/
RUN apk update \
&& apk add --no-cache rsync \
&& mkdir -p /var/log/rsync \
&& rm -rf /var/cache/apk/*
CMD ["/opt/ccmd"]

13
rsync/README.md Normal file
View File

@@ -0,0 +1,13 @@
# 构建 rsync 镜像
## 定制
- 安装 rsync
## 外挂目录和文件
- /etc/rsyncd.conf: rsyncd 配置文件
- /var/log/rsync: rsync 日志目录
- 配置文件中,每个模块里指定的目录也要挂载出来
## 案例
- [Demo/SingleNode/](Demo/SingleNode/): 部署 rsync

67
rsync/rsync.sh Executable file
View File

@@ -0,0 +1,67 @@
#!/bin/bash
#=========================================
# Author : colben
#=========================================
set -euo pipefail
export LANG=en_US.UTF-8
trap Quit EXIT
[ 'x86_64' == "$(uname -m)" ] && ARCH='' || ARCH="-$(uname -m)"
ROOT_DIR="$(cd $(dirname $0) && pwd)"
IMAGE="harbor.colben.cn/general/$(basename ${0%.sh})$ARCH:latest"
if [ -t 0 ]; then
function Print { echo -e "\033[36;1m$(date +'[%F %T]')\033[32;1m $*\033[0m"; }
function Warn { echo -e "\033[36;1m$(date +'[%F %T]')\033[33;1m $*\033[0m"; }
function Error { echo -e "\033[36;1m$(date +'[%F %T]')\033[31;1m $*\033[0m"; exit 1; }
else
function Print { echo -e "$(date +'[%F %T INFO]') $*"; }
function Warn { echo -e "$(date +'[%F %T WARN]') $*"; }
function Error { echo -e "$(date +'[%F %T ERROR]') $*"; exit 1; }
fi
function Quit {
local exitCode=$?
[ 0 -ne $exitCode ] && Error Failed to build or push image!
[ -z "${END:-}" ] && echo && Error Interrupted manually!
Print Succeeded to build and push image.
}
function YesOrNo {
Warn $*
local sw=
while :; do
read -p '(Yes/No/Quit) ' -n1 sw
[[ "$sw" =~ ^Y|y$ ]] && echo && return 0
[[ "$sw" =~ ^N|n$ ]] && echo && return 1
[[ "$sw" =~ ^Q|q$ ]] && echo && exit 0
[ -n "$sw" ] && echo
done
}
function Update {
:
}
function Build {
local yn
cd $ROOT_DIR
docker images --format='{{.Repository}}:{{.Tag}}' | grep "^$IMAGE$" \
&& Warn Removing image $IMAGE ... \
&& docker rmi $IMAGE
Warn Building image: $IMAGE ...
docker build --force-rm --build-arg ARCH="$ARCH" -t $IMAGE .
YesOrNo Push image: $IMAGE? && docker push $IMAGE
}
function Main {
Update
Build
END=1
}
# Start here
Main