Skip to content

Commit

Permalink
exit only if the launchd file not exist
Browse files Browse the repository at this point in the history
Otherwise the agent is not started at all
  • Loading branch information
umbynos committed May 22, 2023
1 parent 038acf6 commit 0efac75
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions config/autostart.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func getLaunchdAgentPath() *paths.Path {
func InstallPlistFile() {
launchdAgentPath := getLaunchdAgentPath()
if !launchdAgentPath.Exist() {
writeLoadExit(launchdAgentPath)
writeLoadExit(launchdAgentPath, true)
} else {
// we already have an existing launchd plist file, so we check if it's updated
launchAgentContent, _ := launchdAgentPath.ReadFile()
Expand All @@ -49,14 +49,14 @@ func InstallPlistFile() {
} else {
log.Infof("the autostart file %s needs to be updated", launchdAgentPath)
removePlistFile()
writeLoadExit(launchdAgentPath)
writeLoadExit(launchdAgentPath, false)
}

}
}

// writeLoadExit function will write the plist file, load it, and then exit, because launchd will start a new instance.
func writeLoadExit(launchdAgentPath *paths.Path) {
// writeLoadExit function will write the plist file, load it, and then exit (if the exit argument is true), because launchd will start a new instance.
func writeLoadExit(launchdAgentPath *paths.Path, exit bool) {
err := writePlistFile(launchdAgentPath)
if err != nil {
log.Error(err)
Expand All @@ -65,8 +65,10 @@ func writeLoadExit(launchdAgentPath *paths.Path) {
if err != nil {
log.Error(err)
} else {
log.Info("Quitting, another instance of the agent has been started by launchd")
os.Exit(0)
if exit {
log.Info("Quitting, another instance of the agent has been started by launchd")
os.Exit(0)
}
}
}
}
Expand Down

0 comments on commit 0efac75

Please sign in to comment.