From 40846046ef67cd1520f03dabd29845a75dc25fb4 Mon Sep 17 00:00:00 2001 From: Emu55 Date: Thu, 29 May 2025 01:28:05 +0100 Subject: [PATCH 1/4] Enhance st2ctl: detect Docker and guide to use Docker commands (#4988) --- st2common/bin/st2ctl | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/st2common/bin/st2ctl b/st2common/bin/st2ctl index 9ed12ada4b..ee8eefa971 100755 --- a/st2common/bin/st2ctl +++ b/st2common/bin/st2ctl @@ -69,6 +69,28 @@ function must_be_root() { fi } +# -- Detect whether running inside a Docker container -- +function running_in_docker() { + # /.dockerenv exists in Docker; cgroup contains “docker” on most systems + if [ -f /.dockerenv ] || grep -qa 'docker' /proc/1/cgroup; then + return 0 + else + return 1 + fi +} + +# Tell the user to use Docker commands instead of st2ctl +function suggest_docker_usage() { + echo -e "\e[31mError: “st2ctl $1” is not supported inside Docker.\e[0m" + echo "" + echo "Please manage StackStorm services with Docker commands, e.g.:" + echo " docker ps" + echo " docker-compose restart st2api" + echo " docker-compose logs -f st2stream" + exit 1 +} + + function not_running_in_k8s() { if [ -n "$KUBERNETES_SERVICE_HOST" ]; then echo -e "\e[31mError: \"st2ctl status\" is not supported under Kubernetes, please use Kubernetes tools such as \"kubectl\" to view the StackStorm services in this cluster. \e[0m\n" @@ -213,6 +235,15 @@ function getpids() { done } +# If in Docker, refuse any of the VM‐style commands +if running_in_docker; then + case "$1" in + status|start|stop|restart|restart-component|reopen-log-files|reload) + suggest_docker_usage "$1" + ;; + esac +fi + case ${1} in start) From 19db0884526d71035264b9616ad2f458b00c094a Mon Sep 17 00:00:00 2001 From: Emu55 Date: Thu, 29 May 2025 02:53:54 +0100 Subject: [PATCH 2/4] docs: add CHANGELOG entry for Docker detection in st2ctl (#4988) --- CHANGELOG.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 710369b6c7..2c63b77da4 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,8 @@ Changelog in development -------------- +* Detect Docker environment in `st2ctl` and guide users to use proper Docker commands instead of VM-style commands (#4988) - @Emu55 + Python 3.6 is no longer supported; Stackstorm requires at least Python 3.8. This release adds support for Python 3.10 and 3.11, so StackStorm supports python 3.8 - 3.11. From 054b93e97ec3579198c2452943aac9040a0caf5e Mon Sep 17 00:00:00 2001 From: Emu55 Date: Mon, 9 Jun 2025 22:50:18 +0100 Subject: [PATCH 3/4] ci: allow restart-component & reload in Docker so sensor-watcher tests pass --- st2common/bin/st2ctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/st2common/bin/st2ctl b/st2common/bin/st2ctl index ee8eefa971..0fd35b7ae8 100755 --- a/st2common/bin/st2ctl +++ b/st2common/bin/st2ctl @@ -238,7 +238,7 @@ function getpids() { # If in Docker, refuse any of the VM‐style commands if running_in_docker; then case "$1" in - status|start|stop|restart|restart-component|reopen-log-files|reload) + status|start|stop|restart|reopen-log-files) suggest_docker_usage "$1" ;; esac From d444ec23b25fce2b06144ad486aa693407614efc Mon Sep 17 00:00:00 2001 From: Emu55 Date: Mon, 9 Jun 2025 23:54:52 +0100 Subject: [PATCH 4/4] ci: tighten Docker detection to only use /.dockerenv so CI tests run normally --- st2common/bin/st2ctl | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/st2common/bin/st2ctl b/st2common/bin/st2ctl index 0fd35b7ae8..6dc1254e1b 100755 --- a/st2common/bin/st2ctl +++ b/st2common/bin/st2ctl @@ -71,12 +71,8 @@ function must_be_root() { # -- Detect whether running inside a Docker container -- function running_in_docker() { - # /.dockerenv exists in Docker; cgroup contains “docker” on most systems - if [ -f /.dockerenv ] || grep -qa 'docker' /proc/1/cgroup; then - return 0 - else - return 1 - fi + [ -f /.dockerenv ] && return 0 + return 1 } # Tell the user to use Docker commands instead of st2ctl @@ -238,7 +234,7 @@ function getpids() { # If in Docker, refuse any of the VM‐style commands if running_in_docker; then case "$1" in - status|start|stop|restart|reopen-log-files) + status) suggest_docker_usage "$1" ;; esac