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 socket
import subprocess import subprocess
import sys import sys
import time
class Cli(contextlib.AbstractContextManager): class Cli(contextlib.AbstractContextManager):
@ -34,6 +35,14 @@ class Cli(contextlib.AbstractContextManager):
prog="container/osbuild-composer", 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 # --[no-]composer-api
self._parser.add_argument( self._parser.add_argument(
"--composer-api", "--composer-api",
@ -325,6 +334,8 @@ class Cli(contextlib.AbstractContextManager):
sockets = self._prepare_sockets() sockets = self._prepare_sockets()
def handler(signum, frame): def handler(signum, frame):
if self.args.shutdown_wait_period:
time.sleep(self.args.shutdown_wait_period)
proc_composer.terminate() proc_composer.terminate()
proc_worker.terminate() proc_worker.terminate()
proc_dnf_json.terminate() proc_dnf_json.terminate()