/
run-purge.sh
63 lines (56 loc) · 2.58 KB
/
run-purge.sh
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
60
61
62
63
#!/bin/bash
LOCK="/home/${USER}/dlrn.lock"
RSYNC_DEST=$(grep rsyncdest /usr/local/share/dlrn/${USER}/projects.ini | awk -F= '{print $2}')
RSYNC_SERVER=$(echo $RSYNC_DEST | awk -F: '{print $1}')
RSYNC_PORT=$(grep rsyncport /usr/local/share/dlrn/${USER}/projects.ini | awk -F= '{print $2}')
set -e
# if any arguments are given, assume console foreground execution
ARG=$1
exec 200>$LOCK
while ! flock -n 200; do
if [ -n "$ARG" ]
then
echo "DLRN ${USER} running, waiting 30 seconds before retrying."
fi
sleep 30
done
if [ ! -d /home/${USER}/dlrn-logs ]; then
mkdir -p /home/${USER}/dlrn-logs
fi
source ~/.venv/bin/activate
if [ -n "$ARG" ]; then
LOGFILE=/home/${USER}/dlrn-logs/dlrn-purge.console.$(date +%s).log
ARGUMENTS=""
else
LOGFILE=/home/${USER}/dlrn-logs/dlrn-purge.$(date +%s).log
ARGUMENTS="--older-than 60 -y --exclude-dirs /home/${USER}/data/repos/current,/home/${USER}/data/repos/consistent,/home/${USER}/data/repos/current-passed-ci,/home/${USER}/data/repos/current-tripleo,/home/${USER}/data/repos/current-tripleo-rdo,/home/${USER}/data/repos/puppet-passed-ci,/home/${USER}/data/repos/current-tripleo-rdo-internal"
fi
cd ~/dlrn
set +e
echo `date` "Starting DLRN-purge run." >> $LOGFILE
if [ -n "${RSYNC_DEST}" ]; then
# First, synchronize promotion-based symlinks from the primary server, which is where promotions run
ssh -p ${RSYNC_PORT} -o StrictHostKeyChecking=no $RSYNC_SERVER "find /home/${USER}/data/repos -maxdepth 1 -type l | grep -v -e current$ -e consistent$ -e delorean-deps.repo$"| while read symlink; do
rsync -avz -e "ssh -p ${RSYNC_PORT} -o StrictHostKeyChecking=no" ${RSYNC_SERVER}:$symlink /home/${USER}/data/repos/
done
fi
# Now, purge as needed
dlrn-purge --config-file /usr/local/share/dlrn/${USER}/projects.ini ${ARGUMENTS} "$@" 2>> $LOGFILE
RET=$?
echo `date` "DLRN-purge run complete." >> $LOGFILE
# If the purge operation was successful, synchronize to the backup node
if [ ${RET} -eq 0 ]; then
# The sync process can be slow, let's do it only once a week, on Sunday
if [ "$(date +%u)" = "7" ]; then
echo `date` "Starting synchronization to backup server." >> $LOGFILE
if [ -n "${RSYNC_DEST}" ]; then
rsync -avz --delete-delay --exclude="*.htaccess" --exclude="/deps" --exclude="/build-deps" -e "ssh -p ${RSYNC_PORT} -o StrictHostKeyChecking=no" /home/${USER}/data/repos/* ${RSYNC_DEST} 2>> $LOGFILE
fi
echo `date` "Synchronization to backup server completed." >> $LOGFILE
fi
fi
if [ -n "$ARG" ]; then
echo Arguments: "$@"
cat $LOGFILE
fi
exit $RET