server/configs/synchro.sh

45 lines
1.4 KiB
Bash
Raw Normal View History

2018-01-19 14:20:39 +00:00
#!/bin/bash
# This script synchronizes first, the generated frontend and then
# retrieves submissions
BASEDIR="/srv"
2023-07-25 05:36:44 +00:00
FRONTEND_HOSTNAME="phobos"
2018-01-19 14:20:39 +00:00
2022-08-06 20:31:18 +00:00
SSH_OPTS="ssh -p 22 -i ~/.ssh/id_ed25519 -o ControlMaster=auto -o ControlPath=/root/.ssh/%r@%h:%p -o ControlPersist=2 -o PasswordAuthentication=no -o StrictHostKeyChecking=no"
2018-01-19 14:20:39 +00:00
cd "${BASEDIR}"
touch /tmp/stop
2018-01-19 14:20:39 +00:00
# Establish first ssh connection for controlpersist socket, to avoid delay during time synchronization
2022-08-06 20:31:18 +00:00
${SSH_OPTS} ${FRONTEND_HOSTNAME} ls > /dev/null
# Synchronize the date one time
2022-08-06 20:31:18 +00:00
${SSH_OPTS} ${FRONTEND_HOSTNAME} date -s @"$(date +%s)"
# Synchronize static files in a separate loop (to avoid submissions delays during file synchronization)
while ! [ -f SETTINGS/stop ] || [ /tmp/stop -nt SETTINGS/stop ]
do
rsync -e "$SSH_OPTS" -av --delete FILES "${FRONTEND_HOSTNAME}":"${BASEDIR}"
# Synchronize logs
rsync -e "$SSH_OPTS" -av "${FRONTEND_HOSTNAME}":/var/log/ /var/log/frontend
sleep 5
done &
2018-01-19 14:20:39 +00:00
while ! [ -f SETTINGS/stop ] || [ /tmp/stop -nt SETTINGS/stop ]
do
# Synchronize static files pages
rsync -e "$SSH_OPTS" -av --delete --delay-updates --partial-dir=.tmp/ PKI TEAMS SETTINGSDIST "${FRONTEND_HOSTNAME}":"${BASEDIR}"
2018-01-19 14:20:39 +00:00
# Synchronize submissions
rsync -e "$SSH_OPTS" -av --ignore-existing --delay-updates --temp-dir=.tmp/ --partial-dir=.tmp/ --remove-source-files "${FRONTEND_HOSTNAME}":"${BASEDIR}"/submissions/ submissions/
2018-01-19 14:20:39 +00:00
sleep 0.3
done
wait
2018-01-19 14:20:39 +00:00
echo See you