update
This commit is contained in:
60
rsync/ADD/ccmd
Executable file
60
rsync/ADD/ccmd
Executable 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
|
||||
|
Reference in New Issue
Block a user