projects
/
mirror
/
dsa-puppet.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
rename dsa-puppet-stuff to puppet-crontab
[mirror/dsa-puppet.git]
/
modules
/
roles
/
files
/
static-mirroring
/
static-master-update-component
diff --git
a/modules/roles/files/static-mirroring/static-master-update-component
b/modules/roles/files/static-mirroring/static-master-update-component
index
e01c734
..
4ab5143
100755
(executable)
--- a/
modules/roles/files/static-mirroring/static-master-update-component
+++ b/
modules/roles/files/static-mirroring/static-master-update-component
@@
-30,12
+30,16
@@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
componentlist=/etc/static-components.conf
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
componentlist=/etc/static-components.conf
-base=/home/staticsync/static-master/master
+. /etc/staticsync.conf
+if ! [ -n "$masterbase" ]; then
+ echo >&2 "masterbase not configured!"
+ exit 1
+fi
set -e
set -u
set -e
set -u
-if [ "`id -u`" != "`stat -c %u "$base"`" ]; then
+if [ "`id -u`" != "`stat -c %u "$
master
base"`" ]; then
echo >&2 "You are probably running this as the wrong user."
exit 1
fi
echo >&2 "You are probably running this as the wrong user."
exit 1
fi
@@
-81,13
+85,21
@@
if [ "${component%/*}" != "$component" ] ; then
exit 1
fi
exit 1
fi
-srchost="$(awk -v this_host="$(hostname -f)" -v component="$component" '$1 == this_host && $2 == component {print $3; exit}' "$componentlist")"
-srcdir="$(awk -v this_host="$(hostname -f)" -v component="$component" '$1 == this_host && $2 == component {print $4; exit}' "$componentlist")"
+srchost="$(awk -v this_host="$(hostname -f)" -v component="$component" '
!/^ *(#|$)/ &&
$1 == this_host && $2 == component {print $3; exit}' "$componentlist")"
+srcdir="$(awk -v this_host="$(hostname -f)" -v component="$component" '
!/^ *(#|$)/ &&
$1 == this_host && $2 == component {print $4; exit}' "$componentlist")"
if [ -z "$srchost" ] || [ -z "$srcdir" ]; then
echo >&2 "$0: Invalid component: $component (not found in $componentlist)";
exit 1
fi
if [ -z "$srchost" ] || [ -z "$srcdir" ]; then
echo >&2 "$0: Invalid component: $component (not found in $componentlist)";
exit 1
fi
-tgt="$base/$component"
+
+tgtlock="$masterbase/$component.lock"
+if ! [ -e "$tgtlock" ]; then
+ touch "$tgtlock"
+fi
+echo "$0: Acquiring lock on $tgtlock..."
+lock 203 "$tgtlock" 1
+
+tgt="$masterbase/$component"
if ! [ -d "$tgt" ]; then
echo "$0: Creating $tgt for $component";
mkdir "$tgt"
if ! [ -d "$tgt" ]; then
echo "$0: Creating $tgt for $component";
mkdir "$tgt"
@@
-99,15
+111,16
@@
else
src="$srchost:$srcdir"
fi
src="$srchost:$srcdir"
fi
-
echo "$0: Acquiring locks
..."
-lock 201 "$tgt" 1
+
#echo "$0: Acquiring lock on $tgt
..."
+
#
lock 201 "$tgt" 1
-tmpdir_new="$(mktemp -d --tmpdir="$base" "${component}-updating.incoming-XXXXXX")"
-tmpdir_old="$(mktemp -d --tmpdir="$base" "${component}-updating.removing-XXXXXX")"
+tmpdir_new="$(mktemp -d --tmpdir="$
master
base" "${component}-updating.incoming-XXXXXX")"
+tmpdir_old="$(mktemp -d --tmpdir="$
master
base" "${component}-updating.removing-XXXXXX")"
trap "rm -rf '$tmpdir_new' '$tmpdir_old'" EXIT
chmod 0755 "$tmpdir_new"
trap "rm -rf '$tmpdir_new' '$tmpdir_old'" EXIT
chmod 0755 "$tmpdir_new"
-lock 202 "$tmpdir_new" 1
+#echo "$0: Acquiring lock on $tmpdir_new..."
+#lock 202 "$tmpdir_new" 1
echo "$0: Got them."
echo "$0: Updating master copy of $component..."
echo "$0: Got them."
echo "$0: Updating master copy of $component..."
@@
-119,11
+132,11
@@
rsync --delete \
"$src/." "$tmpdir_new/."
echo "$0: Done. Committing."
"$src/." "$tmpdir_new/."
echo "$0: Done. Committing."
-mv "$tgt" "$tmpdir_old/old"
-if ! mv "$tmpdir_new" "$tgt"; then
+mv
--no-target-directory
"$tgt" "$tmpdir_old/old"
+if ! mv
--no-target-directory
"$tmpdir_new" "$tgt"; then
echo >&2 "$0: WARNING: could not move $tmpdir_new to $tgt. Trying to recover"
rm -rf "$tgt"
echo >&2 "$0: WARNING: could not move $tmpdir_new to $tgt. Trying to recover"
rm -rf "$tgt"
- mv "$tmpdir_old/old" "$tgt"
+ mv
--no-target-directory
"$tmpdir_old/old" "$tgt"
echo >&2 "$0: Rolled back to old tree, maybe even successfully."
exit 1
fi
echo >&2 "$0: Rolled back to old tree, maybe even successfully."
exit 1
fi
@@
-132,8
+145,9
@@
rm -rf "$tmpdir_new" "$tmpdir_old"
trap - EXIT
date '+%s' > "$tgt/.serial"
trap - EXIT
date '+%s' > "$tgt/.serial"
-unlock 201
-unlock 202
+#unlock 201
+#unlock 202
+unlock 203
echo "$0: Triggering mirror runs..."
exec static-master-run "$component"
echo "$0: Triggering mirror runs..."
exec static-master-run "$component"