diff --git a/primary.py b/primary.py index 6ab686fdf509d465d23bcbb5d98c883eca8c8631..e32f677e20e364c36413e8d0317442d5216aab7e 100644 --- a/primary.py +++ b/primary.py @@ -48,6 +48,7 @@ class Server: self.uuid = uuid self.socket_path = '/tmp/%s_server' % (self.uuid) self.mutex = threading.Lock() + self.failed = None self.thread_hash = None self.thread_star = None self.thread_server = threading.Thread(daemon=True, target=self.run) @@ -72,10 +73,10 @@ class Server: star_socket,_ = server.accept() self.log.DEBUG('CPIO', star_socket) with self.mutex: - self.thread_hash = threading.Thread(daemon=True, + self.thread_star = threading.Thread(daemon=True, target=self.run_star, args=(star_socket,)) - self.thread_hash.start() + self.thread_star.start() cond_unlink(self.socket_path, self.log) @@ -120,6 +121,11 @@ class Server: stdout=stdout, stderr=self.log.makefile(encoding='utf-8')) self.log.DEBUG('OK run_star', cmd, cwd) + except Exception as e: + with self.mutex: + self.failed = True + pass + pass finally: self.log.MESSAGE('shutting down star_socket') star_socket.shutdown(socket.SHUT_RDWR) @@ -137,12 +143,13 @@ class Client: prefix="%s client " % (self.uuid)) self.server_log = loghandler.LOG(parent=log, prefix="%s server " % (self.uuid)) + self.failed = False self.thread = threading.Thread(daemon=True, target=self.run) self.thread.start() def pending(self): return self.thread.is_alive() - + def run(self): self.log.DEBUG('Running', self.entry.dump()) for path in self.entry.path: @@ -189,8 +196,7 @@ class Client: stderr=stderr.makefile(encoding='utf-8')) except: self.log.MESSAGE('DIED %s' % (readable)) - - exit(1) + self.failed = True time.sleep(1) self.log.MESSAGE('DONE %s' % (readable)) time.sleep(1) @@ -223,4 +229,6 @@ def do_backup(hash_name, options, config): while any([ c.pending() for c in client ]): time.sleep(1) + if any([c.failed for c in client]): + raise Exception("Backup failed") diff --git a/secondary.py b/secondary.py index 6265ef9af62a545f97e4df3412f677c47cadf9df..e816932839c5444a971ca9b03df137f1a282a9de 100644 --- a/secondary.py +++ b/secondary.py @@ -9,6 +9,7 @@ import socket import subprocess import time import shutil +import sys def cond_unlink(path, log): try: @@ -55,10 +56,14 @@ class Backup: self.trash = os.path.join(self.trash_root, str(int(time.time())).encode('utf-8')) extract_cmd = [ '/bin/star', '-x', '-nowarn', '-no-statistics' ] - self.extract = subprocess.Popen(extract_cmd, - cwd=os.path.join(mount, path), - stdin=self.primary_out) - atexit.register(cond_kill, self.extract) + try: + self.extract = subprocess.Popen(extract_cmd, + cwd=os.path.join(mount, path), + stdin=self.primary_out) + atexit.register(cond_kill, self.extract) + except: + print('EXIT', file=sys.stderr) + exit(1) # Make sure that the generated star archive is not empty self.primary_in.write(b'.\0')