Kill docker image on SIGTERM.
authorcah <cah@ableton.com>
Tue, 4 Oct 2022 06:53:45 +0000 (08:53 +0200)
committerCarl Hetherington <cth@carlh.net>
Tue, 4 Oct 2022 07:26:00 +0000 (09:26 +0200)
cdist

diff --git a/cdist b/cdist
index 49589b7d7efcd51d5b1be4af8d7a85f39a3f0b13..f814ba890075b28a6f9389a755f9434e9e5b0f08 100755 (executable)
--- a/cdist
+++ b/cdist
@@ -29,6 +29,7 @@ import os
 from pathlib import Path
 import platform
 import re
+import signal
 import shlex
 import shutil
 import subprocess
@@ -549,6 +550,10 @@ class DockerTarget(Target):
         if config.has('docker_hub_repository'):
             tag = '%s:%s' % (config.get('docker_hub_repository'), tag)
 
+        def signal_handler(signum, frame):
+            raise Error('Killed')
+        signal.signal(signal.SIGTERM, signal_handler)
+
         self.container = command_and_read('%s run %s %s -itd %s /bin/bash' % (config.docker(), self._user_tag(), opts, tag))[0].strip()
 
     def command(self, cmd):