wafer wants to be able to write its log, make it run with the debconf-web gid
[mirror/dsa-puppet.git] / modules / roles / files / static-mirroring / static-master-run
index e2a583e..95c9355 100755 (executable)
@@ -9,10 +9,23 @@ import sys
 import tempfile
 import time
 
-base="/srv/static.debian.org"
 serialname = '.serial'
 had_warnings = False
 
+conffile = '/etc/staticsync.conf'
+config={}
+
+with open(conffile) as f:
+  for line in f:
+    line = line.rstrip()
+    if not line or line.startswith("#"): continue
+    (name, value) = line.split("=")
+    config[name] = value
+
+for key in ('base',):
+  if not key in config:
+    raise Exception("Configuration element '%s' not found in config file %s"%(key, conffile))
+
 allclients = set()
 with open('/etc/static-clients.conf') as f:
   for line in f:
@@ -106,7 +119,7 @@ def callout(component, serial, clients):
     stage2(pipes, status, 'abort', clients)
     return False
 
-  failedmirrorsfile = os.path.join(base, 'master', component + "-failedmirrors")
+  failedmirrorsfile = os.path.join(config['base'], 'master', component + "-failedmirrors")
   if 'failed' in cnt:
     log("WARNING: %d clients failed!  Continuing anyway!"%(cnt['failed'],))
     global had_warnings
@@ -152,7 +165,7 @@ def run_mirror(component):
   clients = allclients - meta['extraignoreclients']
 
   # setup
-  basemaster = os.path.join(base, 'master')
+  basemaster = os.path.join(config['base'], 'master')
   componentdir = os.path.join(basemaster, component)
   cur = componentdir + '-current-push'
   live = componentdir + '-current-live'
@@ -161,14 +174,25 @@ def run_mirror(component):
   os.chmod(tmpdir_new, 0755)
 
   locks = []
-  for p in (componentdir, live, tmpdir_new):
-    if not os.path.exists(p): os.mkdir(p, 0755)
+  lockfiles = [ os.path.join(basemaster, component + ".lock") ]
+  for p in lockfiles:
     fd = os.open(p, os.O_RDONLY)
     log("Acquiring lock for %s(%d)."%(p,fd))
     fcntl.flock(fd, fcntl.LOCK_EX)
     locks.append(fd)
   log("All locks acquired.")
 
+  for p in (live, ):
+    if not os.path.exists(p): os.mkdir(p, 0755)
+
+  #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))
+  #  fcntl.flock(fd, fcntl.LOCK_EX)
+  #  locks.append(fd)
+  #log("All locks acquired.")
+
   serialfile = os.path.join(componentdir, serialname)
   try:
     with open(serialfile) as f: serial = int(f.read())