import subprocess import os import re import signal retries = 0 total = 5 patterns = [ r"getSourceReport: $.*$ Service has disappeared", r"xvfb-run: line .*: kill: \(.*\) - No such process", r"cp: cannot create directory '/work/firka': Permission denied" ] while True: try: retries += 1 if retries != 1: print(f"Attempt {retries}/{total}") if retries >= 5: print("Retry count exhausted") exit(-1) process = subprocess.Popen(["docker-compose", "up", "--build"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) while True: output = process.stdout.readline() if output == '' and process.poll() is not None: break if output: print(output.strip()) for pattern in patterns: if re.search(pattern, output): print(f"Matched pattern: {pattern}") process.send_signal(signal.SIGINT) break rc = process.poll() if rc == 0: exit(0) else: print(f"docker-compose exited with code {rc}") except subprocess.CalledProcessError as e: print(f"Error running docker-compose: {e}")