-
Notifications
You must be signed in to change notification settings - Fork 601
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
limactl start: add --foreground
flag
#2146
limactl start: add --foreground
flag
#2146
Conversation
cmd/limactl/start.go
Outdated
return err | ||
} | ||
if foreground { | ||
ctx = start.WithLaunchHostAgentForeground(ctx, foreground) |
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.
Is there any reason to use a context for this?
Wondering if we can just add an argument to start.Start()
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.
There's no particular reason. I just mimicked the way the timeout
flag is written.
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.
The timeout is contextualized because it has to be passed to many functions.
This is different from the foreground flag that is only used once.
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.
Understood, I'll try changing it.
Please squash the commits |
324d034
to
3a74a52
Compare
cmd/limactl/edit.go
Outdated
@@ -122,7 +122,7 @@ func editAction(cmd *cobra.Command, args []string) error { | |||
if err != nil { | |||
return err | |||
} | |||
return start.Start(ctx, inst) | |||
return start.Start(ctx, inst, start.DefaultLaunchHostAgentForeground) |
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.
Would it be better if the --foreground
flag was also available for limactl edit
?
pkg/start/start.go
Outdated
@@ -33,6 +35,10 @@ import ( | |||
// to be running before timing out. | |||
const DefaultWatchHostAgentEventsTimeout = 10 * time.Minute | |||
|
|||
// DefaultLaunchHostAgentForeground is the default value of the boolean to use for | |||
// Start() | |||
const DefaultLaunchHostAgentForeground = false |
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.
No need to define this const
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.
Thanks
This change adds the `--foreground` flag to `limactl start`. This flag: - Launches `limactl hostagent` with `syscall.Exec`, which allows `limactl start --foreground` to be used in macOS's `launchd.plist`, making it possible to hide `limactl hostagent`. - When launched from the terminal, it uses the terminal for standard output and standard error instead of the default `ha.std{out,err}.log` files. In this case, a message indicating that the default log files are not used is written to the log files. - When launched from something other than the terminal, such as `launchd`, it uses the `ha.std{out,err}.log` files as before. - Cannot be used on Windows. The following are the updated steps to set up the Docker instance of Lima to start at login using launchd on macOS: ```bash # Create the docker instance limactl create template://docker --vm-type vz --rosetta --network vzNAT --tty=false # Create the launchd plist echo '<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>io.lima-vm.docker</string> <key>ProgramArguments</key> <array> <string>'"$(which limactl)"'</string> <string>start</string> <string>--foreground</string> <string>docker</string> </array> <key>RunAtLoad</key> <true/> <key>StandardErrorPath</key> <string>launchd.stderr.log</string> <key>StandardOutPath</key> <string>launchd.stdout.log</string> <key>WorkingDirectory</key> <string>'"$(limactl list docker --format '{{.Dir}}')"'</string> </dict> </plist>' > ~/Library/LaunchAgents/io.lima-vm.docker.plist # Load the launchd plist and launchd will start the docker instance launchctl load ~/Library/LaunchAgents/io.lima-vm.docker.plist ``` that changed from lima-vm#2140: - Changed to `limactl create` because it's no longer necessary to run `limactl start` before loading into `launchd`. - Changed from `limactl hostagent` to `limactl start --foreground`. - Changed `Standard{Error,Out}Path` to `launchd.std{err,out}.log`, so that only the output of `limactl start` is written. Signed-off-by: Norio Nomura <norio.nomura@gmail.com> Update cmd/limactl/start.go Change `instance` to `hostagent` Co-authored-by: Akihiro Suda <suda.kyoto@gmail.com> Add `launchHostAgentForeground` to `start.Start()` Avoid using `Context` to passing `launchHostAgentForeground` Remove `start.DefaultLaunchHostAgentForeground`
3a74a52
to
599712b
Compare
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.
Thanks, LGTM
if err := haCmd.Start(); err != nil { | ||
if launchHostAgentForeground { | ||
logrus.Info("Running the host agent in the foreground") | ||
if isatty.IsTerminal(os.Stdin.Fd()) || isatty.IsCygwinTerminal(os.Stdin.Fd()) { |
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.
I wonder if it is time to create a wrapper for this condition:
$ ag IsCygwin
cmd/limactl/main.go
82: if runtime.GOOS == "windows" && isatty.IsCygwinTerminal(os.Stdout.Fd()) {
cmd/limactl/list.go
171: if isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd()) {
cmd/limactl/shell.go
176: if isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd()) {
pkg/progressbar/progressbar.go
15: if isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd()) {
pkg/qemu/entitlementutil/entitlementutil.go
88: if isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd()) {
Not sure what the right package is, maybe uiutil.isatty()
?
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.
Yes, but it can be another PR
Thanks! 🙏🏻 |
This change adds the
--foreground
flag tolimactl start
.This flag:
limactl hostagent
withsyscall.Exec
, which allowslimactl start --foreground
to be used in macOS'slaunchd.plist
, making it possible to hidelimactl hostagent
.ha.std{out,err}.log
files. In this case, a message indicating that the default log files are not used is written to the log files.launchd
, it uses theha.std{out,err}.log
files as before.The following are the updated steps to set up the Docker instance of Lima to start at login using launchd on macOS:
that changed from #2140:
limactl create
because it's no longer necessary to runlimactl start
before loading intolaunchd
.limactl hostagent
tolimactl start --foreground
.Standard{Error,Out}Path
tolaunchd.std{err,out}.log
, so that only the output oflimactl start
is written.