This commit is contained in:
2021-09-07 14:50:23 -04:00
commit 37658cfaca
54 changed files with 2918 additions and 0 deletions

12
rsync/Dockerfile Normal file
View File

@@ -0,0 +1,12 @@
FROM alpine:latest
RUN apk add --no-cache --virtual .run-deps rsync openssh tzdata curl ca-certificates flock bash && rm -rf /var/cache/apk/*
COPY docker-entrypoint.sh /
COPY litestream /usr/local/bin/litestream
RUN chmod +x /docker-entrypoint.sh
RUN chmod +x /usr/local/bin/litestream
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["bash"]

2
rsync/README.md Normal file
View File

@@ -0,0 +1,2 @@
[![Build Status](http://droneci.service.dc1.consul/api/badges/sstent/rsync/status.svg)](http://droneci.service.dc1.consul/sstent/rsync)
Tue Sep 7 13:57:20 EDT 2021

117
rsync/docker-entrypoint.sh Executable file
View File

@@ -0,0 +1,117 @@
#!/bin/bash
################################################################################
# INIT
################################################################################
# mkdir -p /root/.ssh
# > /root/.ssh/authorized_keys
# chmod go-rwx /root/.ssh/authorized_keys
# sed -i "s/#PasswordAuthentication yes/PasswordAuthentication no/g" /etc/ssh/sshd_config
# sed -i 's/root:!/root:*/' /etc/shadow
# Provide SSH_AUTH_KEY_* via environment variable
for item in `env`; do
case "$item" in
SSH_AUTH_KEY*)
ENVVAR=`echo $item | cut -d \= -f 1`
printenv $ENVVAR >> /root/.ssh/authorized_keys
;;
esac
done
# Provide CRON_TASK_* via environment variable
> /etc/crontabs/root
for item in `env`; do
case "$item" in
CRON_TASK*)
ENVVAR=`echo $item | cut -d \= -f 1`
printenv $ENVVAR >> /etc/crontabs/root
echo "root" > /etc/crontabs/cron.update
;;
esac
done
# Generate host SSH keys
# if [ ! -e /etc/ssh/ssh_host_rsa_key.pub ]; then
# ssh-keygen -A
# fi
# Generate root SSH key
# if [ ! -e /root/.ssh/id_rsa.pub ]; then
# ssh-keygen -q -N "" -f /root/.ssh/id_rsa
# fi
################################################################################
# START as SERVER
################################################################################
# if [ "$1" == "server" ]; then
# AUTH=`cat /root/.ssh/authorized_keys`
# if [ -z "$AUTH" ]; then
# echo "=================================================================================="
# echo "ERROR: No SSH_AUTH_KEY provided, you'll not be able to connect to this container. "
# echo "=================================================================================="
# exit 1
# fi
# SSH_PARAMS="-D -e -p ${SSH_PORT:-22} $SSH_PARAMS"
# echo "================================================================================"
# echo "Running: /usr/sbin/sshd $SSH_PARAMS "
# echo "================================================================================"
# exec /usr/sbin/sshd -D $SSH_PARAMS
# fi
# echo "Please add this ssh key to your server /home/user/.ssh/authorized_keys "
# echo "================================================================================"
# echo "`cat /root/.ssh/id_rsa.pub`"
# echo "================================================================================"
################################################################################
# START as CLIENT via crontab
################################################################################
if [ "$1" == "client" ]; then
exec /usr/sbin/crond -f
fi
if [ "$NOMAD_TASK_NAME" == "init" ]; then
echo "Starting RSYNC"
flock -x /locks/${NOMAD_GROUP_NAME}_rsync.lock rsync -avv --exclude=Backups --exclude='*.db*' --exclude='*.db' --exclude='*db-litestream' --exclude='generations' /configbackup/ /config/ --delete-before --delete-excluded
echo "Ensure no DBs"
rm -rf /config/*.db*
rm -rf /config/database.sqlite
echo "Starting DB Restore"
/usr/local/bin/litestream restore -config /local/litestream.yml /config/${DB_NAME}
chown ${PUID:-1000}:${PGID:-1000} /config/*.db*
if [ -n "$DBCHMOD" ]; then
chmod ${DBCHMOD} /config/${DB_NAME:${NOMAD_GROUP_NAME}}.db;
fi
exit 0
fi
if [ "$NOMAD_TASK_NAME" == "finalsync" ]; then
echo "Starting RSYNC"
flock -x /locks/${NOMAD_GROUP_NAME}_rsync.lock rsync -avv --exclude=Backups --exclude='*.db*' --exclude='*.db' --exclude='*db-litestream' --exclude='generations' /config/ /configbackup/
exit 0
fi
if [ "$NOMAD_TASK_NAME" == "db-sync" ]; then
echo "Starting DBsync: sleep"
#give time for app to datart properly
sleep 1m
echo "Starting DBsync"
exec flock -x /configbackup/${NOMAD_GROUP_NAME}_litesync.lock /usr/local/bin/litestream replicate -config /local/litestream.yml
exit 0
fi
################################################################################
# Anything else
################################################################################
exec "$@"

BIN
rsync/litestream Executable file

Binary file not shown.