From: cah Date: Tue, 4 Oct 2022 06:53:45 +0000 (+0200) Subject: Kill docker image on SIGTERM. X-Git-Url: https://git.carlh.net/gitweb/?a=commitdiff_plain;ds=sidebyside;h=e9ac3d457a6b01566cef008dae9ab77059a8652a;p=cdist.git Kill docker image on SIGTERM. --- diff --git a/cdist b/cdist index 49589b7..f814ba8 100755 --- 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):