Skip to content

Commit 21b691e

Browse files
committed
exit only if the launchd file not exist
Otherwise the agent is not started at all
1 parent 038acf6 commit 21b691e

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

config/autostart.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ func getLaunchdAgentPath() *paths.Path {
3939
func InstallPlistFile() {
4040
launchdAgentPath := getLaunchdAgentPath()
4141
if !launchdAgentPath.Exist() {
42-
writeLoadExit(launchdAgentPath)
42+
writeAndLoadPlistFile(launchdAgentPath)
43+
log.Info("Quitting, another instance of the agent has been started by launchd")
44+
os.Exit(0)
4345
} else {
4446
// we already have an existing launchd plist file, so we check if it's updated
4547
launchAgentContent, _ := launchdAgentPath.ReadFile()
@@ -49,24 +51,21 @@ func InstallPlistFile() {
4951
} else {
5052
log.Infof("the autostart file %s needs to be updated", launchdAgentPath)
5153
removePlistFile()
52-
writeLoadExit(launchdAgentPath)
54+
writeAndLoadPlistFile(launchdAgentPath)
5355
}
5456

5557
}
5658
}
5759

58-
// writeLoadExit function will write the plist file, load it, and then exit, because launchd will start a new instance.
59-
func writeLoadExit(launchdAgentPath *paths.Path) {
60+
// writeAndLoadPlistFile function will write the plist file, load it, and then exit, because launchd will start a new instance.
61+
func writeAndLoadPlistFile(launchdAgentPath *paths.Path) {
6062
err := writePlistFile(launchdAgentPath)
6163
if err != nil {
6264
log.Error(err)
6365
} else {
6466
err = loadLaunchdAgent() // this will load the agent: basically starting a new instance
6567
if err != nil {
6668
log.Error(err)
67-
} else {
68-
log.Info("Quitting, another instance of the agent has been started by launchd")
69-
os.Exit(0)
7069
}
7170
}
7271
}

0 commit comments

Comments
 (0)