Skip to content

Enhance st2ctl Docker detection and usage hints (#4988) #6334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Emu55
Copy link

@Emu55 Emu55 commented May 29, 2025

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

  1. Docker detection helper
    Added a new function running_in_docker() which returns success if either:

    • The file /.dockerenv is present, or
    • The string “docker” appears in /proc/1/cgroup
  2. Usage suggestion helper
    Added suggest_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
  3. Early exit for VM-style commands
    Inserted a pre-dispatch check before the main case "$1" in … esac block:

    if running_in_docker; then
      case "$1" in
        status|start|stop|restart|restart-component|reopen-log-files|reload)
          suggest_docker_usage "$1"
          ;;
      esac
    fi

@pull-request-size pull-request-size bot added the size/M PR that changes 30-99 lines. Good size to review. label May 29, 2025
@CLAassistant
Copy link

CLAassistant commented May 29, 2025

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
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.

@pull-request-size pull-request-size bot added size/S PR that changes 10-29 lines. Very easy to review. and removed size/M PR that changes 30-99 lines. Good size to review. labels Jun 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/S PR that changes 10-29 lines. Very easy to review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants