]> git.donarmstrong.com Git - dsa-puppet.git/blobdiff - modules/roles/files/static-mirroring/static-master-run
Prevent python from releasing locks prematurely
[dsa-puppet.git] / modules / roles / files / static-mirroring / static-master-run
index 24ea3e11b1a02d42c4896c06e49a0e86952f7d40..c82d68849e1003c1b30c9f2dc58d1b7069cd0a2a 100755 (executable)
@@ -5,6 +5,7 @@ import os
 import shutil
 import subprocess
 import string
+import sys
 import tempfile
 import time
 
@@ -15,9 +16,12 @@ subdirs = { 'master': 'master',       # where updates from off-site end up going
 serialname = '.serial'
 
 clients = []
-with open('/home/staticsync/etc/static-clients') as f:
+with open('/etc/static-clients.conf') as f:
   for line in f:
-    clients.append(line.strip())
+    line = line.strip()
+    if line == "": continue
+    if line.startswith('#'): continue
+    clients.append(line)
 
 def log(m):
   t = time.strftime("[%Y-%m-%d %H:%M:%S]", time.gmtime())
@@ -119,7 +123,7 @@ def run_mirror():
   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.new-', dir=base); cleanup_dirs.append(tmpdir_old);
+  tmpdir_old = tempfile.mkdtemp(prefix='live.old-', dir=base); cleanup_dirs.append(tmpdir_old);
   os.chmod(tmpdir_new, 0755)
 
   locks = []
@@ -159,15 +163,26 @@ def run_mirror():
     log("Cleaning up.")
     shutil.rmtree(tmpdir_old)
     log("Done.")
+    ret = True
   else:
     log("Aborted.")
+    ret = False
 
+  for fd in locks:
+    fd.close()
 
+  return ret
+
+
+ok = False
 try:
-  run_mirror()
+  ok = run_mirror()
 finally:
   for p in cleanup_dirs:
     if os.path.exists(p): shutil.rmtree(p)
+
+if not ok:
+  sys.exit(1)
 # vim:set et:
 # vim:set ts=2:
 # vim:set shiftwidth=2: