From 86d219ada7ec716b36a7085456992aaed555e244 Mon Sep 17 00:00:00 2001 From: Davlet Panech Date: Thu, 15 Feb 2024 14:28:54 -0500 Subject: [PATCH] stx control stop: faster shutdown Make sure aptly & builder containers catch and handle SIGTERM. Otherwise "stx stop" sends the signal, 2 out of 6 containers ignore it, then docker waits for ~15 seconds and SIGKILL's them. * stx-builder.Dockerfile: change default image command from plain "bash" to "tini" that starts "sleep infinity". Tini catches and broadcasts signals to its own children (sleep), enabling graceful shutdown to work * aptly: replace call to "supervisord" to "exec supervisord", to make sure it runs as PID 1 and actually receives signals from docker. * stx_control.py: slightly reduce loop sleep time in "stx control stop" TESTS ================== * Retest "stx control start --wait" * Make sure builder's entry point executes "finisSetup.sh" script, as before this change * Make sure "stx control stop --wait" exits quickly (~4 seconds on my machine, down from ~15 seconds) Story: 2011038 Task: 49577 Signed-off-by: Davlet Panech Change-Id: I984846fc45349be045c069b84186f12179fe36ad --- stx/dockerfiles/stx-builder.Dockerfile | 4 ++++ stx/lib/stx/k8s.py | 2 +- stx/lib/stx/stx_control.py | 2 +- stx/toCOPY/aptly/entrypoint.sh | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/stx/dockerfiles/stx-builder.Dockerfile b/stx/dockerfiles/stx-builder.Dockerfile index e6903e0b..21e074a4 100644 --- a/stx/dockerfiles/stx-builder.Dockerfile +++ b/stx/dockerfiles/stx-builder.Dockerfile @@ -51,6 +51,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y \ rpm2cpio \ ssh \ sudo \ + tini \ unzip \ vim \ wget \ @@ -97,3 +98,6 @@ RUN apt-key add /root/pubkey.rsa && rm -f /root/pubkey.rsa RUN mkdir -p /etc/vim COPY stx/toCOPY/common/vimrc.local /etc/vim/vimrc.local RUN chmod 0644 /etc/vim/vimrc.local + +ENTRYPOINT ["/usr/bin/tini", "-g", "--"] +CMD ["/bin/bash", "-i", "-c", "exec /bin/sleep infinity" ] diff --git a/stx/lib/stx/k8s.py b/stx/lib/stx/k8s.py index 7cb6ce25..a3e3b215 100644 --- a/stx/lib/stx/k8s.py +++ b/stx/lib/stx/k8s.py @@ -80,7 +80,7 @@ class KubeHelper: suffix='.stderr') as stderr_file: cmd = f'{self.config.kubectl()} get pods --no-headers' cmd += f' --selector=app.kubernetes.io/instance={project_name} 2>{stderr_file.name}' - process_result = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE) + process_result = subprocess.run(cmd, encoding='utf-8', shell=True, stdout=subprocess.PIPE) if process_result.returncode != 0: logger.error('Command failed: %s\n%s', cmd, stderr_file.fread()) raise RuntimeError("Failed to list pods") diff --git a/stx/lib/stx/stx_control.py b/stx/lib/stx/stx_control.py index f3c30e33..36325f2b 100644 --- a/stx/lib/stx/stx_control.py +++ b/stx/lib/stx/stx_control.py @@ -306,7 +306,7 @@ stx-pkgbuilder/configmap/') self.logger.warning("gave up while pods are still running") break self.logger.info("waiting for %d pod(s) to exit", pod_count) - time.sleep(3) + time.sleep(2) def handleIsStartedTask(self, projectname): if self.k8s.helm_release_exists(projectname): diff --git a/stx/toCOPY/aptly/entrypoint.sh b/stx/toCOPY/aptly/entrypoint.sh index 321af57f..3af011d3 100755 --- a/stx/toCOPY/aptly/entrypoint.sh +++ b/stx/toCOPY/aptly/entrypoint.sh @@ -39,4 +39,4 @@ else fi # Start Supervisor -/usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf +exec /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf