-
Notifications
You must be signed in to change notification settings - Fork 263
[cloud] ssh shim part 4: detect stopped vm, and terminate mutagen sessions #352
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
Conversation
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
a0daaf8
to
1c84d2e
Compare
94078a7
to
5f8aff3
Compare
78d54e9
to
9d0aa27
Compare
5f8aff3
to
04fe82f
Compare
9d0aa27
to
7162db4
Compare
04fe82f
to
b78cf72
Compare
7162db4
to
f7f504b
Compare
84b95fd
to
daa80bf
Compare
newEnv = append(newEnv, fmt.Sprintf("%s=%s", k, v)) | ||
// envAsKeyValueStrings prepares the env-vars in key=value format to add to the command to be run | ||
// | ||
// panics if os.Environ() returns an array with any element not in key=value format |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it really cannot, hence I thought it was acceptable to have the panic.
for _, cmdEnv := range cmd.Env { | ||
if strings.HasPrefix(cmdEnv, "MUTAGEN_SSH") { | ||
if strings.HasPrefix(cmdEnv, "MUTAGEN") { | ||
envPrint = fmt.Sprintf("%s\n", cmdEnv) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this will always print the last MUTAGEN_*
env var instead of all of them. Is that intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha, yup, it was for this PR. In one of the subsequent PRs, I fixed it to print all of them.
cloud/openssh/sshshim/mutagen.go
Outdated
|
||
err := cmd.Run() | ||
if err != nil { | ||
if err.Error() == "exit status 255" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you unwrap this to an exec.ExitError
you can check the exit code directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes, I had meant to do this, but forgot to update the code. Updated!
cloud/openssh/sshshim/mutagen.go
Outdated
|
||
func checkActiveVM(vmAddr string) (bool, error) { | ||
|
||
cmd := exec.Command("ssh", vmAddr, "echo 'alive'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to use exec.CommandContext
so you can enforce a timeout on the health check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call! Added
… to check ExitCode
4613c2a
to
6524f8e
Compare
Summary
This PR adds logic for the
sshshim
to check for a live VM. If the VM is not reachable,then it should terminate the sync session. We label each sync with the machineID
so that cloud-shells to the same vm get the same label for their mutagen sync.
To test for liveness, I currently execute a
echo "alive"
command in the VM. Thereare likely better ways to do this. Suggestions welcome!
NOTE:
For now, I pass-thru the ssh/scp command if the arguments indicate that the server
is not a devbox-vm. In the next PR, I'll see if we can have a dedicated mutagen daemon
via setting MUTAGEN_DATA_DIRECTORY, in which case we can more strongly impose
that the ssh/scp command can be executed only with a liveVM. UPDATE: this works!
NOTE:
I also discovered that I need to manually empty-out the MUTAGEN_PROMPTER env-var.
This is done, because mutagen otherwise will expect a certain (interactive?) prompt
in the arguments to the mutagen CLI. Mutagen does set this env-var on all ssh/scp executions, but I'm a bit unclear on why this is hooked up.
How was it tested?
ensure no active mutagen daemon (next PR should take away this step)
manually start a vm (command omitted due to closed source, but happy to share)
DEVBOX_FEATURE_SSH_SHIM=1 DEVBOX_VM=username@vmaddress devbox cloud shell
cd ~/.config/devbox/ssh/shims
andtail -f logs.txt
to monitor the shim.exit the cloud shell
fly m stop <id>
to stop the vmtouch foo.txt
in the devbox project folder to trigger a sync actionwait for the
logs.txt
to show themutagen sync terminate
command.~/.cache/mutagen/bin/mutagen sync list
to confirm the session is terminated.