containers/osbuild-composer: Allow shutdown wait period

Openshift keeps sending requests to composer for a while after it has
sent SIGTERM, this results in requests being reset randomly on
shutdown. Waiting a few seconds before terminating mitigates this.
This commit is contained in:
Sanne Raymaekers 2022-07-01 20:01:35 +02:00
parent ad847a6fca
commit 595de8ed7f

View file

@ -14,6 +14,7 @@ import signal
import socket
import subprocess
import sys
import time
class Cli(contextlib.AbstractContextManager):
@ -34,6 +35,14 @@ class Cli(contextlib.AbstractContextManager):
prog="container/osbuild-composer",
)
self._parser.add_argument(
"--shutdown-wait-period",
type=int,
default=0,
dest="shutdown_wait_period",
help="Wait period in seconds before terminating child processes",
)
# --[no-]composer-api
self._parser.add_argument(
"--composer-api",
@ -325,6 +334,8 @@ class Cli(contextlib.AbstractContextManager):
sockets = self._prepare_sockets()
def handler(signum, frame):
if self.args.shutdown_wait_period:
time.sleep(self.args.shutdown_wait_period)
proc_composer.terminate()
proc_worker.terminate()
proc_dnf_json.terminate()