]> git.donarmstrong.com Git - dsa-puppet.git/commitdiff
Try to allow for individual pushes of static components at the cost of having a singl...
authorPeter Palfrader <peter@palfrader.org>
Thu, 25 Apr 2013 12:15:37 +0000 (14:15 +0200)
committerPeter Palfrader <peter@palfrader.org>
Thu, 25 Apr 2013 12:21:59 +0000 (14:21 +0200)
modules/roles/files/static-mirroring/static-components.conf
modules/roles/files/static-mirroring/static-master-run
modules/roles/files/static-mirroring/static-master-ssh-wrap
modules/roles/files/static-mirroring/static-master-update-component
modules/roles/files/static-mirroring/static-mirror-run
modules/roles/files/static-mirroring/static-mirror-ssh-wrap
modules/roles/manifests/static_mirror.pp

index f028ff2d0000bcc1b38119efdf366e9202bec2a9..e4a1d6196106ee54f61e086d838347f4e85167f7 100644 (file)
@@ -1,8 +1,8 @@
 # puppetd maintained
-# <service> <source host> <directory> <extra push hosts, comma separated>
+# <master> <service> <source host> <directory> <extra push hosts, comma separated>
 
-mozilla.debian.net     wagner.debian.org       /srv/home/groups/pkg-mozilla/htdocs
-planet.debian.org      senfl.debian.org        /srv/planet.debian.org/www
-www.debian.org         wolkenstein.debian.org  /srv/www.debian.org/www
-bits.debian.org                master.debian.org       /srv/bits-master.debian.org/htdocs
-backports.debian.org   ries.debian.org         /srv/backports.debian.org/htdocs                franck.debian.org
+bizet.debian.org       mozilla.debian.net      wagner.debian.org       /srv/home/groups/pkg-mozilla/htdocs
+bizet.debian.org       planet.debian.org       senfl.debian.org        /srv/planet.debian.org/www
+bizet.debian.org       www.debian.org          wolkenstein.debian.org  /srv/www.debian.org/www
+bizet.debian.org       bits.debian.org         master.debian.org       /srv/bits-master.debian.org/htdocs
+bizet.debian.org       backports.debian.org    ries.debian.org         /srv/backports.debian.org/htdocs                franck.debian.org
index 027f38468abd174912738100115c3b29db5dcddd..fab3baa404e41c6e4e2651f86afafa0ba462ad80 100755 (executable)
@@ -10,9 +10,6 @@ import tempfile
 import time
 
 base='/home/staticsync/static-master'
-subdirs = { 'master': 'master',       # where updates from off-site end up going, the source of everything we do here
-            'cur':    'current-push', # where clients rsync from during a mirror push
-            'live':   'current-live'} # what is currently on the mirrors, and what they rsync from when they come back from being down
 serialname = '.serial'
 
 clients = []
@@ -88,12 +85,12 @@ def stage2(pipes, status, command):
       log("%s >> %s"%(c, l))
     log("%s: returned %d"%(c, p.returncode))
 
-def callout(serial):
+def callout(component, serial):
   log("Calling clients...")
   pipes = {}
   status = {}
   for c in clients:
-    args = ['ssh', '-o', 'BatchMode=yes', c, 'mirror', "%d"%(serial,)]
+    args = ['ssh', '-o', 'BatchMode=yes', c, 'mirror', component, "%d"%(serial,)]
     p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
     pipes[c] = p
     status[c] = 'in-progress'
@@ -117,17 +114,18 @@ def callout(serial):
 
 
 cleanup_dirs = []
-def run_mirror():
+def run_mirror(component):
   # setup
-  master = os.path.join(base, subdirs['master'])
-  cur = os.path.join(base, subdirs['cur'])
-  live = os.path.join(base, subdirs['live'])
-  tmpdir_new = tempfile.mkdtemp(prefix='live.new-', dir=base); cleanup_dirs.append(tmpdir_new);
-  tmpdir_old = tempfile.mkdtemp(prefix='live.old-', dir=base); cleanup_dirs.append(tmpdir_old);
+  basemaster = os.path.join(base, 'master')
+  componentdir = os.path.join(basemaster, component)
+  cur = componentdir + '-current-push'
+  live = componentdir + '-current-live'
+  tmpdir_new = tempfile.mkdtemp(prefix='live.new-', dir=basemaster); cleanup_dirs.append(tmpdir_new);
+  tmpdir_old = tempfile.mkdtemp(prefix='live.old-', dir=basemaster); cleanup_dirs.append(tmpdir_old);
   os.chmod(tmpdir_new, 0755)
 
   locks = []
-  for p in (master, live, tmpdir_new):
+  for p in (componentdir, live, tmpdir_new):
     if not os.path.exists(p): os.mkdir(p, 0755)
     fd = os.open(p, os.O_RDONLY)
     log("Acquiring lock for %s(%d)."%(p,fd))
@@ -135,7 +133,7 @@ def run_mirror():
     locks.append(fd)
   log("All locks acquired.")
 
-  serialfile = os.path.join(master, serialname)
+  serialfile = os.path.join(componentdir, serialname)
   try:
     with open(serialfile) as f: serial = int(f.read())
   except:
@@ -144,7 +142,7 @@ def run_mirror():
   log("Serial is %s."%(serial,))
 
   log("Populating %s."%(tmpdir_new,))
-  subprocess.check_call(['cp', '-al', os.path.join(master, '.'), tmpdir_new])
+  subprocess.check_call(['cp', '-al', os.path.join(componentdir, '.'), tmpdir_new])
 
   if os.path.exists(cur):
     log("Removing existing %s."%(cur,))
@@ -153,7 +151,7 @@ def run_mirror():
   log("Renaming %s to %s."%(tmpdir_new, cur))
   os.rename(tmpdir_new, cur)
 
-  proceed = callout(serial)
+  proceed = callout(component, serial)
 
   if proceed:
     log("Moving %s aside."%(live,))
@@ -174,9 +172,14 @@ def run_mirror():
   return ret
 
 
+if len(sys.argv) != 2:
+  print >> sys.stderr, "Usage: %s <component>"%(sys.argv[0],)
+  sys.exit(1)
+component = sys.argv[1]
+
 ok = False
 try:
-  ok = run_mirror()
+  ok = run_mirror(component)
 finally:
   for p in cleanup_dirs:
     if os.path.exists(p): shutil.rmtree(p)
index 625d3d9b5df10229db79bf5637f68714f5784b8d..8387560b0f38863e976d800f9b2d0643179763e5 100755 (executable)
@@ -72,22 +72,26 @@ lock() {
 
 do_rsync() {
        local remote_host="$1"; shift
-
        local args="--server --sender -vlHtrze.iLsf --safe-links ."
-       if [ "$*" = "$args -new-/" ] || [ "$*" = "$args ./-new-/" ] ; then
-               local path="$BASEDIR/current-push"
-               info "serving $remote_host with $path"
-               rsync $args "$path/."
-       elif [ "$*" = "$args . -live-/" ] || [ "$*" = "$args . ./-live-/" ] ; then
-               local path="$BASEDIR/current-live"
-               info "host $remote_host wants $path, acquiring lock"
-               lock 200 "$path" 0
-               rsync $args "$path/."
-       else
-               info "NOT allowed for $remote_host: rsync $*"
-               echo >&2 "This rsync command ($@) not allowed."
-               exit 1
-       fi
+
+       for component in $(awk -v this_host="$(hostname -f)" '$1 == this_host {print $2}' $COMPONENTLIST); do
+         if [ "$*" = "$args $component/-new-/" ] || [ "$*" = "$args ./$component/-new-/" ] ; then
+                 local path="$BASEDIR/$component-current-push"
+                 info "serving $remote_host with $path"
+                 rsync $args "$path/."
+                 return
+         elif [ "$*" = "$args . $component/-live-/" ] || [ "$*" = "$args . ./$component/-live-/" ] ; then
+                 local path="$BASEDIR/$component-current-live"
+                 info "host $remote_host wants $path, acquiring lock"
+                 lock 200 "$path" 0
+                 rsync $args "$path/."
+                 return
+         fi
+       done
+
+       info "NOT allowed for $remote_host: rsync $*"
+       echo >&2 "This rsync command ($@) not allowed."
+       exit 1
 }
 
 do_update_component() {
@@ -98,16 +102,16 @@ do_update_component() {
        shift
 
        hit="$(
-               awk -v component="$component" -v host="$remote_host" '
-                 $1 == component {
-                         if ($2 == host) {
-                                 print $3
+               awk -v this_host="$(hostname -f)" component="$component" -v host="$remote_host" '
+                 $1 == this_host && $2 == component {
+                         if ($3 == host) {
+                                 print $4
                                  exit
                          }
-                         split($4,extra,",")
+                         split($5,extra,",")
                          for (i in extra) {
                                  if (host == extra[i]) {
-                                         printf "%s:%s\n", $2, $3
+                                         printf "%s:%s\n", $3, $4
                                          exit
                                  }
                          }
index f2ea1165367cbf69edf5a1561210edcf4e81fc33..82bae0d81041f67791993553cff09b2f14b84ce3 100755 (executable)
@@ -54,7 +54,7 @@ lock() {
   fi
 
   if ! flock "$locktype" "$fd"; then
-    echo >&2 "$0: Cannot acquire lock on $base (flock $locktype failed) - Very bad, we should have waited!"
+    echo >&2 "$0: Cannot acquire lock on $path (flock $locktype failed) - Very bad, we should have waited!"
     exit 1
   fi
 }
@@ -81,8 +81,8 @@ if [ "${component%/*}" != "$component" ] ; then
   exit 1
 fi
 
-srchost="$(awk -v component="$component" '$1 == component {print $2; exit}' "$componentlist")"
-srcdir="$(awk -v component="$component" '$1 == component {print $3; exit}' "$componentlist")"
+srchost="$(awk -v this_host="$(hostname -f)" component="$component" '$1 == this_host && $2 == component {print $3; exit}' "$componentlist")"
+srcdir="$(awk -v this_host="$(hostname -f)" 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
@@ -100,11 +100,10 @@ else
 fi
 
 echo "$0: Acquiring locks..."
-lock 200 "$base" 0
 lock 201 "$tgt" 1
 
-tmpdir_new="$(mktemp -d --tmpdir="$base" "${component}.new-XXXXXX")"
-tmpdir_old="$(mktemp -d --tmpdir="$base" "${component}.old-XXXXXX")"
+tmpdir_new="$(mktemp -d --tmpdir="$base" "${component}-updating.incoming-XXXXXX")"
+tmpdir_old="$(mktemp -d --tmpdir="$base" "${component}-updating.removing-XXXXXX")"
 trap "rm -rf '$tmpdir_new' '$tmpdir_old'" EXIT
 chmod 0755 "$tmpdir_new"
 
@@ -116,6 +115,7 @@ rsync --delete \
   -trz \
   --links --hard-links --safe-links \
   --link-dest="$tgt" \
+  --exclude='/.serial' \
   "$src/." "$tmpdir_new/."
 echo "$0: Done.  Committing."
 
@@ -124,18 +124,18 @@ if ! mv "$tmpdir_new" "$tgt"; then
   echo >&2 "$0: WARNING: could not move $tmpdir_new to $tgt.  Trying to recover"
   rm -rf "$tgt"
   mv "$tmpdir_old/old" "$tgt"
-  echo >&2 "$0: Rolled back to old tree maybe successfully."
+  echo >&2 "$0: Rolled back to old tree, maybe even successfully."
   exit 1
 fi
 
 rm -rf "$tmpdir_new" "$tmpdir_old"
 trap - EXIT
 
-date '+%s' > "$base/.serial"
+date '+%s' > "$tgt/.serial"
 unlock 201
-unlock 200
+unlock 202
 echo "$0: Triggering mirror runs..."
-exec static-master-run
+exec static-master-run "$component"
 
 # vim:set et:
 # vim:set ts=2:
index 038700ddb73a4497e61b7ab834a9011823f8783f..72f7aea610e7f500a05c87fa488abf9024c4001f 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-# initiate a mirror staged mirror update from sync-source.
+# initiate a staged mirror update from sync-source for a component.
 #
 # if we have a serial file and we got a serial on the command line, only sync if the serial is different
 
@@ -119,16 +119,18 @@ lock() {
 
 
 log_setup
-#log "called with $* and ${SSH_ORIGINAL_COMMAND:-no ssh original command options}."
 log "called with $*"
 lock
 
 if [ -e "${BASEDIR}${ACTIVE}" ] && [ "$(readlink "${BASEDIR}${ACTIVE}")" = "$ALPHA" ] ; then
        staging="$BRAVO"
        active="$ALPHA"
-else
+elif [ -e "${BASEDIR}${ACTIVE}" ] && [ "$(readlink "${BASEDIR}${ACTIVE}")" = "$BRAVO" ] ; then
        staging="$ALPHA"
        active="$BRAVO"
+else
+       echo >&5 "Invalid state of ${BASEDIR}${ACTIVE}."
+       exit 1
 fi
 log "active is $active; staging is $staging"
 
index 240fefec8389e45d48c6ad7304b3fa273c3e9e84..b4c8447b878e1eef63e4808348c83cf88c5aca2b 100755 (executable)
@@ -36,7 +36,9 @@ COMPONENTLIST=/etc/static-components.conf
 usage() {
        echo "local Usage: $0 <basedir> <host>"
        echo "via ssh orig command:"
-       echo "                      mirror <serial>"
+       echo "                      mirror <component> <serial>"
+       echo "                      rsync ..."
+               do_rsync "$remote_host" "$@"
 }
 
 one_more_arg() {
@@ -59,10 +61,12 @@ do_mirror() {
        local basedir="$1"; shift
        local remote_host="$1"; shift
        one_more_arg "$@"
+       local component="$1"; shift
+       one_more_arg "$@"
        local serial="$1"; shift
 
-       info "Host $remote_host triggered a mirror run for serial $serial"
-       exec /usr/local/bin/static-mirror-run "$basedir" "$remote_host:-new-" "$serial"
+       info "Host $remote_host triggered a mirror run for $component, serial $serial"
+       exec /usr/local/bin/static-mirror-run "$basedir" "$remote_host:$component/-new-" "$serial"
        echo >&2 "Exec failed"
        croak "exec failed"
 }
@@ -75,7 +79,7 @@ do_rsync() {
        allowed_rsyncs=()
 
        if [ -e "$COMPONENTLIST" ]; then
-               for path in $(awk -v host="$(hostname -f)" '$2 == host {print $3}' $COMPONENTLIST); do
+               for path in $(awk -v host="$(hostname -f)" '$3 == host {print $4}' $COMPONENTLIST); do
                        allowed_rsyncs+=("--server --sender -lHtrze.iLsf --safe-links . $path/.")
                done
        fi
index 8dd1bb850ce13ad7e45ec9c86bfcc6d344e40dd1..c8d9335aa6c02116fe5ca7a984fb43150a7996d7 100644 (file)
@@ -24,7 +24,7 @@ class roles::static_mirror {
        }
 
        file { '/etc/cron.d/puppet-static-mirror':
-                       content => "PATH=/usr/local/bin:/usr/bin:/bin\n@reboot staticsync sleep 60; static-mirror-run --one-stage /srv/static.debian.org bizet.debian.org:-live- > /dev/null\n",
+                       content => "PATH=/usr/local/bin:/usr/bin:/bin\n@reboot staticsync sleep 60; for a in `awk '!/^ *(#|$)/ {printf "%s:%s/-live-\n", $1, $2}' /etc/static-components.conf`; do static-mirror-run --one-stage /srv/static.debian.org "$a" > /dev/null; done\n",
        }
 
        $vhost_listen = $::hostname ? {