-
Notifications
You must be signed in to change notification settings - Fork 706
autostart: Ensure instance is started/stopped by launchd
or systemctl
#4139
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
Open
norio-nomura
wants to merge
3
commits into
lima-vm:master
Choose a base branch
from
norio-nomura:improve-autostart
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+677
−254
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
783c0f2
to
428fcb1
Compare
How to test this PR? |
Also please explain what issue is being solved by this PR |
opened #4141 |
ac9db28
to
31d7007
Compare
1cea297
to
b4e6288
Compare
- Hide creating/deleting an autostart entry file into `Register`/`Unregister` as the implementation details. - Separate the `launchd` and `systemd`-specific code into packages. Signed-off-by: Norio Nomura <[email protected]>
…ctl` If the instance isn’t launched by `launchd`, it won’t be stopped on log out. This changes to use `launchctl` or `systemctl` to start/stop the instance if it’s registered to autostart. ## Affected sub commands: - `limactl start` - `limactl stop` - `limactl restart` - `limactl edit` - `limactl shell` ## API changes ### `pkg/autostart` - Introduced `AutoStartedIdentifier()`: - If not empty, it indicates whether the instance was started by `launchd` or `systemd`. - Added `RequestStart()`: - Delegates the operation to `launchd` or `systemd`. - Added `RequestStop()`: - Delegates the operation to `launchd` or `systemd`. ### `pkg/autostart/launchd` - Added `AutoStartedServiceName()`: - Uses the XPC_SERVICE_NAME environment variable as the service name. - Added `RequestStart()`: - Uses `launchctl enable service-target` to avoid failing `bootstrap`. - Uses `launchctl bootstrap domain-target plist-path`. - Added `RequestStop()`: - Uses `launchctl bootout service-target` if the instance is launched by `launchd`. - Added `--progress` to the `limactl` option in `io.lima-vm.autostart.INSTANCE.plist`: - Required to support `limactl start --progress`. ### `pkg/autostart/systemd` - Added `AutoStartedServiceName()`: - Uses `CurrentUnitName()` by `github.com/coreos/go-systemd/v22/util` as the service identifier. - Added `RequestStart()`: - Uses `systemctl --user start unit-name`. - Added `RequestStop()`: - Uses `systemctl --user stop unit-name` if the instance is launched by `systemd`. - Added `--progress` to the `limactl` option in `[email protected]`: - Required to support `limactl start --progress`. ### `pkg/hostagent` - Add `AutoStartedIdentifier` to `Info`. - If not empty, it indicates whether the instance was started by `launchd` or `systemd`. ### `pkg/instance` - `StartWithPaths()`: - Use `autostart.IsRegistered()` to check if the instance is registered to autostart. - If `launchHostAgentForeground` is true, ignore autostart registration. - If the instance is registered to autostart, use `autostart.RequestStart()` instead of launching HostAgent. - `StopGracefully()`: - Use `autostart.RequestStop()`. - `Restart()`, `RestartForcibly()`: - Use `autostart.IsRegistered()` to skip `networks.Reconcile()` if the instance is registered to autostart. Signed-off-by: Norio Nomura <[email protected]>
…hctl bootstrap` Because instances may be stopped without unloading the plist file. e.g. `limactl stop -f` or `limactl factory-reset`. If the plist file is not unloaded, `launchctl bootstrap` will fail. Signed-off-by: Norio Nomura <[email protected]>
b4e6288
to
89c500c
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is formed with two parts:
autoStartManager
to prepare for the following commitlaunchd
orsystemctl
Refactor to add
autoStartManager
Register
/Unregister
as the implementation details.launchd
andsystemd
-specific code into packages.Use
launchctl
orsystemctl
to start/stop the instance if it’s registered to autostart.If the instance isn’t launched by
launchd
, it won’t be stopped on log out.Affected sub commands:
limactl start
limactl stop
limactl restart
limactl edit
limactl shell
API changes
pkg/autostart
AutoStartedIdentifier()
:launchd
orsystemd
.RequestStart()
:launchd
orsystemd
.RequestStop()
:launchd
orsystemd
.pkg/autostart/launchd
AutoStartedServiceName()
:RequestStart()
:launchctl enable service-target
to avoid failingbootstrap
.launchctl bootstrap domain-target plist-path
.RequestStop()
:launchctl bootout service-target
if the instance is launched bylaunchd
.--progress
to thelimactl
option inio.lima-vm.autostart.INSTANCE.plist
:limactl start --progress
.pkg/autostart/systemd
AutoStartedServiceName()
:CurrentUnitName()
bygithub.com/coreos/go-systemd/v22/util
as the service identifier.RequestStart()
:systemctl --user start unit-name
.RequestStop()
:systemctl --user stop unit-name
if the instance is launched bysystemd
.--progress
to thelimactl
option in[email protected]
:limactl start --progress
.pkg/hostagent
AutoStartedIdentifier
toInfo
.launchd
orsystemd
.pkg/instance
StartWithPaths()
:autostart.IsRegistered()
to check if the instance is registered to autostart.launchHostAgentForeground
is true, ignore autostart registration.autostart.RequestStart()
instead of launching HostAgent.StopGracefully()
:autostart.RequestStop()
.Restart()
,RestartForcibly()
:autostart.IsRegistered()
to skipnetworks.Reconcile()
if the instance is registered to autostart.