Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
osterman committed Dec 22, 2015
0 parents commit d0f8c82
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Dockerfile
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"]

61 changes: 61 additions & 0 deletions start
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


0 comments on commit d0f8c82

Please sign in to comment.