Skip to content

monit-docker --cmd does not propagate inner command exit code #7

Description

@kfeina

Title: monit-docker --cmd does not propagate inner command exit code

When using monit-docker monit --cmd, the exit code of the command executed inside the container is captured and printed in the ExecResult(exit_code=...) output, but it is not propagated as the exit code of monit-docker itself.

Example:

/usr/local/bin/monit-docker \
  --name signal-cli-rest-api-signal-cli-rest-api-1 \
  monit \
  --cmd '(bash -c "exit 1")'

echo $?

Current behavior:

INFO: ... ExecResult(exit_code=1, output=b'')
0

So the inner command failed with exit code 1, but monit-docker exits 0.

This makes it impossible to use --cmd directly from Monit check program, because Monit only sees the wrapper exit code and cannot react to the actual result of the command executed inside the container.

Expected behavior:

monit-docker should exit with the same exit code as the command executed inside the container, or alternatively provide an option such as:

--propagate-exit-code

so that:

monit-docker ... --cmd '(bash -c "exit 1")'
echo $?

would return:

1

This would make --cmd usable directly from Monit and other automation tools without requiring wrapper scripts that parse ExecResult(exit_code=...).

So basically the following doesn't work:

check program docker.signal-cli-rest-api.tmpfs with path "/usr/local/bin/monit-docker --name signal-cli-rest-api-signal-cli-rest-api-1 monit --cmd '(bash -c "/usr/local/bin/monit-checkFS-tmp.sh")' "
    if status != 0 for 2 cycles then alert
    group monit-dockers

root@slp-mon01:/etc/monit# monit status docker.signal-cli-rest-api.tmpfs
Monit 5.34.4 uptime: 2h 26m

Program 'docker.signal-cli-rest-api.tmpfs'
  status                       OK
  monitoring status            Monitored
  monitoring mode              active
  on reboot                    laststate
  last exit value              0
  last output                  INFO:2026-04-08 14:16:47: execute 'bash -c "/usr/local/bin/monit-checkFS-tmp.sh"' in signal-cli-rest-api-signal-cli-rest-api-1
                               INFO:2026-04-08 14:16:47: 'bash -c "/usr/local/bin/monit-checkFS-tmp.sh"' executed in signal-cli-rest-api-signal-cli-rest-api-1: ExecResult(exit_code=1, output=b'/tmp usage is  99% (> 80%)\n')
  data collected               Wed, 08 Apr 2026 14:17:44

Environment:

  • monit-docker version: 0.50
  • Docker host: Ubuntu
  • Use case: monitor /tmp usage inside a container with a custom script returning 0 or 1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions