st2
st2 copied to clipboard
Enhance st2ctl Docker detection and usage hints (#4988)
Enhance st2ctl Docker detection and usage hints
This pull request adds support for detecting when st2ctl is being run inside a Docker container and, for VM-style commands, immediately exits with a clear error message and guidance on the proper Docker commands to use.
Background
The st2ctl script was originally written to manage StackStorm services on a single host or VM, using tools like ps, systemctl, or direct process checks. In containerized deployments, each StackStorm component runs in its own Docker container, so those VM-style operations:
- Fail or return misleading results when run inside a container
- Don’t reflect the recommended Docker-native workflow
Issue #4988 requests that st2ctl detect this scenario and provide helpful Docker-specific guidance instead of attempting unsupported operations.
What’s Changed
-
Docker detection helper
Added a new functionrunning_in_docker()which returns success if either:- The file
/.dockerenvis present, or - The string “docker” appears in
/proc/1/cgroup
- The file
-
Usage suggestion helper
Addedsuggest_docker_usage(subcommand)which:- Prints a red-highlighted error:
Error: “st2ctl <subcommand>” is not supported inside Docker. - Prints examples of the correct Docker commands to manage services:
docker ps docker-compose restart st2api docker-compose logs -f st2stream - Exits with status code
1
- Prints a red-highlighted error:
-
Early exit for VM-style commands
Inserted a pre-dispatch check before the maincase "$1" in … esacblock:if running_in_docker; then case "$1" in status|start|stop|restart|restart-component|reopen-log-files|reload) suggest_docker_usage "$1" ;; esac fi
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.