@@ -18,6 +18,7 @@ import (
18
18
"github.com/lima-vm/lima/pkg/ioutilx"
19
19
"github.com/lima-vm/lima/pkg/sshutil"
20
20
"github.com/lima-vm/lima/pkg/store"
21
+ "github.com/lima-vm/sshocker/pkg/ssh"
21
22
"github.com/mattn/go-isatty"
22
23
"github.com/sirupsen/logrus"
23
24
"github.com/spf13/cobra"
@@ -49,6 +50,7 @@ func newShellCommand() *cobra.Command {
49
50
50
51
shellCmd .Flags ().String ("shell" , "" , "shell interpreter, e.g. /bin/bash" )
51
52
shellCmd .Flags ().String ("workdir" , "" , "working directory" )
53
+ shellCmd .Flags ().Bool ("reconnect" , false , "reconnect to the SSH session" )
52
54
return shellCmd
53
55
}
54
56
@@ -81,6 +83,24 @@ func shellAction(cmd *cobra.Command, args []string) error {
81
83
return fmt .Errorf ("instance %q is stopped, run `limactl start %s` to start the instance" , instName , instName )
82
84
}
83
85
86
+ restart , err := cmd .Flags ().GetBool ("restart-ssh" )
87
+ if err != nil {
88
+ return err
89
+ }
90
+ if restart {
91
+ logrus .Infof ("Exiting ssh session for the instance %q" , instName )
92
+
93
+ sshConfig := & ssh.SSHConfig {
94
+ ConfigFile : inst .SSHConfigFile ,
95
+ Persist : false ,
96
+ AdditionalArgs : []string {},
97
+ }
98
+
99
+ if err := ssh .ExitMaster (inst .Hostname , inst .SSHLocalPort , sshConfig ); err != nil {
100
+ return err
101
+ }
102
+ }
103
+
84
104
// When workDir is explicitly set, the shell MUST have workDir as the cwd, or exit with an error.
85
105
//
86
106
// changeDirCmd := "cd workDir || exit 1" if workDir != ""
0 commit comments