-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart
executable file
·61 lines (50 loc) · 1.11 KB
/
start
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
RSYNC_INTERVAL=${RSYNC_INTERVAL:-0}
RSYNC_VOL="${RSYNC_VOL:-/vol}"
RSYNC_PID_FILE="$RSYNC_VOL/.rsync.pid"
RSYNC_ARGV=$@
RSYNC_ARGC=$#
function do_rsync() {
if [ $RSYNC_ARGC -gt 0 ]; then
echo "Performing rsync $RSYNC_ARGV"
rsync $RSYNC_ARGV
else
echo "Skipping rsync; no arguments passed"
fi
}
function do_cleanup() {
if [ -f $RSYNC_PID_FILE ]; then
rm -f $RSYNC_PID_FILE;
fi
}
function do_shutdown() {
kill -SIGINT $RSYNC_PID
}
function do_main() {
(
do_cleanup
while true; do
echo "$$" > "$RSYNC_PID_FILE"
if [ "$RSYNC_INTERVAL" == "on-exit" ]; then
sleep infinity
elif [ "$RSYNC_INTERVAL" == "infinity" ] || [ "$RSYNC_INTERVAL" -gt 0 ]; then
do_rsync;
sleep "$RSYNC_INTERVAL"
else
do_rsync;
break
fi
done
)&
RSYNC_PID=$!
}
do_main
# trap interrupts, do final rsync and quit
trap "echo -e '\nInterrupted'; do_shutdown" SIGINT SIGTERM
wait
if [ "$RSYNC_INTERVAL" == "on-exit" ] || [ "$RSYNC_INTERVAL" == "infinity" ] || [ "$RSYNC_INTERVAL" -gt 0 ]; then
# do one final rsync
do_rsync
fi
# cleanup before we exit
do_cleanup