-
Notifications
You must be signed in to change notification settings - Fork 717
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
Changes from all commits
d9a122b
45d7799
ff3f3a6
0e11d6e
3eb1197
1613e09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,8 +7,8 @@ package main | |||||||
|
|
||||||||
| import ( | ||||||||
| "errors" | ||||||||
| "fmt" | ||||||||
| "os" | ||||||||
| "runtime" | ||||||||
|
|
||||||||
| "github.com/sirupsen/logrus" | ||||||||
| "github.com/spf13/cobra" | ||||||||
|
|
@@ -38,18 +38,24 @@ func startAtLoginAction(cmd *cobra.Command, args []string) error { | |||||||
| if err != nil { | ||||||||
| return err | ||||||||
| } | ||||||||
| if startAtLogin { | ||||||||
| if err := autostart.CreateStartAtLoginEntry(ctx, runtime.GOOS, inst.Name, inst.Dir); err != nil { | ||||||||
| logrus.WithError(err).Warnf("Can't create an autostart file for instance %q", inst.Name) | ||||||||
| } else { | ||||||||
| logrus.Infof("The autostart file %q has been created or updated", autostart.GetFilePath(runtime.GOOS, inst.Name)) | ||||||||
| if registered, err := autostart.IsRegistered(ctx, inst); err != nil { | ||||||||
| return fmt.Errorf("failed to check if the autostart entry for instance %q is registered: %w", inst.Name, err) | ||||||||
| } else if startAtLogin { | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The linter rule should be subject to |
||||||||
| verb := "create" | ||||||||
| if registered { | ||||||||
| verb = "update" | ||||||||
| } | ||||||||
| if err := autostart.RegisterToStartAtLogin(ctx, inst); err != nil { | ||||||||
| return fmt.Errorf("failed to %s the autostart entry for instance %q: %w", verb, inst.Name, err) | ||||||||
| } | ||||||||
| logrus.Infof("The autostart entry for instance %q has been %sd", inst.Name, verb) | ||||||||
| } else { | ||||||||
| deleted, err := autostart.DeleteStartAtLoginEntry(ctx, runtime.GOOS, instName) | ||||||||
| if err != nil { | ||||||||
| logrus.WithError(err).Warnf("The autostart file %q could not be deleted", instName) | ||||||||
| } else if deleted { | ||||||||
| logrus.Infof("The autostart file %q has been deleted", autostart.GetFilePath(runtime.GOOS, instName)) | ||||||||
| if !registered { | ||||||||
| logrus.Infof("The autostart entry for instance %q is not registered", inst.Name) | ||||||||
| } else if err := autostart.UnregisterFromStartAtLogin(ctx, inst); err != nil { | ||||||||
| return fmt.Errorf("failed to unregister the autostart entry for instance %q: %w", inst.Name, err) | ||||||||
| } else { | ||||||||
| logrus.Infof("The autostart entry for instance %q has been unregistered", inst.Name) | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
|
|
||||||||
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.
This logic seems to be repeated in several places. Should it be part of
reconcile.Reconcile()instead?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 are several
reconcile.Reconcile()calls that are not related toautostart.IsRegistered().It is not good to put it in
reconcile.Reconcile().