kamal
kamal copied to clipboard
Add in a server exec command for running ad-hoc commands directly on the server
This PR adds a kamal server exec
command to the CLI which was mentioned in this discussion thread: https://github.com/basecamp/kamal/discussions/371
Running an interactive command against the server, same option that you pass for an accessory or app container:
$ kamal server exec --interactive "/bin/bash"
Running '/bin/bash' on 867.53.0.9 interactively...
root@server-1:~#
Running a command across all matching servers/roles/etc., output is displayed for each host:
$ kamal server exec "date"
Running 'date' on 867.53.0.9...
INFO [8c0d0725] Running /usr/bin/env date on 867.53.0.9
INFO [8c0d0725] Finished in 0.192 seconds with exit status 0 (successful).
App Host: 867.53.0.9
Mon May 13 20:45:58 UTC 2024
You can pass all of the usual filters such as role or host to target those specific servers:
$ kamal server exec "date" -r web
Running 'date' on 867.53.0.9...
INFO [62769fed] Running /usr/bin/env date on 867.53.0.9
INFO [62769fed] Finished in 0.182 seconds with exit status 0 (successful).
App Host: 867.53.0.9
Mon May 13 20:55:41 UTC 2024
Looks great @nickhammond 🙏
I think we should go ahead with the interactive version as well though - would you be able to add that?
@djmb Yah, I'll explore that this week when I get some time.
can't wait for this to be released. It's a small thing, but very crucial for us.
Thank you @nickhammond
@djmb Perhaps the interactive version could be merged as a followup in order to proceed with this PR?
Hi @nickhammond and @djmb,
Is there anything remaining in this PR or blocking? we would love to use it as soon as possible.
Thank you so much!
@djmb Just added in the interactive version with run_locally
. I'm not super familiar with SSHKit so if there's a better way to do this let me know. It mirrors the same options and flow that you'd normally use with an accessory or an app container to run exec.
Thanks @nickhammond!