-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d0f8c82
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM ubuntu:14.04 | ||
|
||
MAINTAINER Erik Osterman "[email protected]" | ||
|
||
ENV RSYNC_INTERVAL 0 | ||
ENV RSYNC_PASSWORD foobar | ||
|
||
VOLUME /vol | ||
|
||
RUN apt-get update && \ | ||
apt-get -y install rsync | ||
|
||
ADD /start /start | ||
|
||
ENTRYPOINT ["/start"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/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 | ||
|
||
|