Skip to content

Commit 7374528

Browse files
authored
Merge pull request #3331 from unsuman/feat/exit-ssh-session
feat: add support for exiting ssh session
2 parents 0cff556 + fc974a5 commit 7374528

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

cmd/limactl/shell.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
networks "github.com/lima-vm/lima/pkg/networks/reconcile"
2121
"github.com/lima-vm/lima/pkg/sshutil"
2222
"github.com/lima-vm/lima/pkg/store"
23+
"github.com/lima-vm/sshocker/pkg/ssh"
2324
"github.com/mattn/go-isatty"
2425
"github.com/sirupsen/logrus"
2526
"github.com/spf13/cobra"
@@ -51,6 +52,7 @@ func newShellCommand() *cobra.Command {
5152

5253
shellCmd.Flags().String("shell", "", "shell interpreter, e.g. /bin/bash")
5354
shellCmd.Flags().String("workdir", "", "working directory")
55+
shellCmd.Flags().Bool("reconnect", false, "reconnect to the SSH session")
5456
return shellCmd
5557
}
5658

@@ -107,6 +109,24 @@ func shellAction(cmd *cobra.Command, args []string) error {
107109
}
108110
}
109111

112+
restart, err := cmd.Flags().GetBool("reconnect")
113+
if err != nil {
114+
return err
115+
}
116+
if restart {
117+
logrus.Infof("Exiting ssh session for the instance %q", instName)
118+
119+
sshConfig := &ssh.SSHConfig{
120+
ConfigFile: inst.SSHConfigFile,
121+
Persist: false,
122+
AdditionalArgs: []string{},
123+
}
124+
125+
if err := ssh.ExitMaster(inst.Hostname, inst.SSHLocalPort, sshConfig); err != nil {
126+
return err
127+
}
128+
}
129+
110130
// When workDir is explicitly set, the shell MUST have workDir as the cwd, or exit with an error.
111131
//
112132
// changeDirCmd := "cd workDir || exit 1" if workDir != ""

0 commit comments

Comments
 (0)