X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=modules%2Froles%2Ffiles%2Fstatic-mirroring%2Fstatic-master-run;h=f8f2be36ab71d4b93ebf6a94c2f03f7ae9aaed0c;hb=16f6c01700c35252542a31c7d739a0ec5a984e92;hp=027f38468abd174912738100115c3b29db5dcddd;hpb=462182438f9c1984cc2d227669fd7a05ecee7c19;p=mirror%2Fdsa-puppet.git diff --git a/modules/roles/files/static-mirroring/static-master-run b/modules/roles/files/static-mirroring/static-master-run index 027f38468..f8f2be36a 100755 --- a/modules/roles/files/static-mirroring/static-master-run +++ b/modules/roles/files/static-mirroring/static-master-run @@ -9,10 +9,7 @@ import sys 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 +base="/srv/static.debian.org" 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=component+'-live.new-', dir=basemaster); cleanup_dirs.append(tmpdir_new); + tmpdir_old = tempfile.mkdtemp(prefix=component+'-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 "%(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)