Merge "Ensure consistent mirroring across config-data"
This commit is contained in:
commit
50665b9816
|
@ -298,7 +298,8 @@ if not os.path.exists(sh_script):
|
|||
# Create a reference timestamp to easily find all files touched by
|
||||
# puppet. The sync ensures we get all the files we want due to
|
||||
# different timestamp.
|
||||
origin_of_time=/var/lib/config-data/${NAME}.origin_of_time
|
||||
conf_data_path="/var/lib/config-data/${NAME}"
|
||||
origin_of_time="${conf_data_path}.origin_of_time"
|
||||
touch $origin_of_time
|
||||
sync
|
||||
|
||||
|
@ -352,7 +353,7 @@ if not os.path.exists(sh_script):
|
|||
|
||||
exclude_files=""
|
||||
for p in $password_files; do
|
||||
if [ -f "$p" -a -f "/var/lib/config-data/${NAME}$p" ]; then
|
||||
if [ -f "$p" -a -f "${conf_data_path}$p" ]; then
|
||||
exclude_files+=" --exclude=$p"
|
||||
fi
|
||||
done
|
||||
|
@ -366,23 +367,36 @@ if not os.path.exists(sh_script):
|
|||
fi
|
||||
done
|
||||
|
||||
echo "Rsyncing config files from ${rsync_srcs} into /var/lib/config-data/${NAME}"
|
||||
rsync -a $verbosity -R --delay-updates --delete-after $exclude_files $rsync_srcs /var/lib/config-data/${NAME}
|
||||
echo "Evaluating config files to be removed for the $NAME configuration"
|
||||
TMPFILE=$(mktemp /tmp/tmp.XXXXXXXXXX)
|
||||
TMPFILE2=$(mktemp /tmp/tmp.XXXXXXXXXX)
|
||||
trap 'rm -rf $TMPFILE $TMPFILE2' EXIT INT HUP
|
||||
rsync -av -R --dry-run --delete-after $exclude_files $rsync_srcs ${conf_data_path} |\
|
||||
awk '/^deleting/ {print $2}' > $TMPFILE
|
||||
|
||||
echo "Rsyncing config files from ${rsync_srcs} into ${conf_data_path}"
|
||||
rsync -a $verbosity -R --delay-updates --delete-after $exclude_files $rsync_srcs ${conf_data_path}
|
||||
|
||||
|
||||
# Also make a copy of files modified during puppet run
|
||||
# This is useful for debugging
|
||||
echo "Gathering files modified after $(stat -c '%y' $origin_of_time)"
|
||||
mkdir -p /var/lib/config-data/puppet-generated/${NAME}
|
||||
|
||||
# Purge obsoleted contents to maintain a fresh and filtered mirror
|
||||
puppet_generated_path=/var/lib/config-data/puppet-generated/${NAME}
|
||||
mkdir -p ${puppet_generated_path}
|
||||
echo "Ensuring the removed config files are also purged in ${puppet_generated_path}:"
|
||||
cat $TMPFILE | sort
|
||||
cat $TMPFILE | xargs -n1 -r -I{} \
|
||||
bash -c "test -f ${puppet_generated_path}/{} && rm -f ${puppet_generated_path}/{}"
|
||||
exec 5>&1
|
||||
exec 1>/tmp/files_from
|
||||
exec 1>$TMPFILE2
|
||||
find $rsync_srcs -newer $origin_of_time -not -path '/etc/puppet*' -print0
|
||||
exec 1>&5
|
||||
echo "Files modified during puppet run:"
|
||||
cat /tmp/files_from | sort | xargs -0 printf "%s\n"
|
||||
echo "Rsyncing the modified files into /var/lib/config-data/puppet-generated/${NAME}"
|
||||
cat $TMPFILE2 | xargs -0 printf "%s\n" | sort -h
|
||||
echo "Rsyncing the modified files into ${puppet_generated_path}"
|
||||
rsync -a $verbosity -R -0 --delay-updates --delete-after $exclude_files \
|
||||
--files-from=/tmp/files_from / /var/lib/config-data/puppet-generated/${NAME}
|
||||
--files-from=$TMPFILE2 / ${puppet_generated_path}
|
||||
|
||||
# Write a checksum of the config-data dir, this is used as a
|
||||
# salt to trigger container restart when the config changes
|
||||
|
@ -404,10 +418,10 @@ if not os.path.exists(sh_script):
|
|||
# output because otherwise the sed command cannot work. The sed is
|
||||
# needed because puppet puts timestamps as comments in cron and
|
||||
# parsedfile resources, hence triggering a change at every redeploy
|
||||
tar -c --mtime='1970-01-01' $EXCLUDE -f - /var/lib/config-data/${NAME} $additional_checksum_files | tar xO | \
|
||||
sed '/^#.*HEADER.*/d' | md5sum | awk '{print $1}' > /var/lib/config-data/${NAME}.md5sum
|
||||
tar -c --mtime='1970-01-01' $EXCLUDE -f - /var/lib/config-data/puppet-generated/${NAME} $additional_checksum_files --mtime='1970-01-01' | tar xO \
|
||||
| sed '/^#.*HEADER.*/d' | md5sum | awk '{print $1}' > /var/lib/config-data/puppet-generated/${NAME}.md5sum
|
||||
tar -c --mtime='1970-01-01' $EXCLUDE -f - ${conf_data_path} $additional_checksum_files | tar xO | \
|
||||
sed '/^#.*HEADER.*/d' | md5sum | awk '{print $1}' > ${conf_data_path}.md5sum
|
||||
tar -c --mtime='1970-01-01' $EXCLUDE -f - ${puppet_generated_path} $additional_checksum_files --mtime='1970-01-01' | tar xO \
|
||||
| sed '/^#.*HEADER.*/d' | md5sum | awk '{print $1}' > ${puppet_generated_path}.md5sum
|
||||
fi
|
||||
""")
|
||||
|
||||
|
|
Loading…
Reference in New Issue