launch properly if previous session crashed and left lock file in place
This commit is contained in:
+10
-3
@@ -53,11 +53,18 @@ func (a *App) VersionTag() string {
|
|||||||
func StartupApp(appName, appVersionTag, configFile, latestReleaseURL string) (*App, error) {
|
func StartupApp(appName, appVersionTag, configFile, latestReleaseURL string) (*App, error) {
|
||||||
sessionPath := configdir.LocalConfig(appName, sessionDir)
|
sessionPath := configdir.LocalConfig(appName, sessionDir)
|
||||||
if _, err := os.Stat(path.Join(sessionPath, sessionLockFile)); err == nil {
|
if _, err := os.Stat(path.Join(sessionPath, sessionLockFile)); err == nil {
|
||||||
log.Println("Another instance is running. Reactivating it and exiting...")
|
log.Println("Another instance is running. Reactivating it...")
|
||||||
if f, err := os.Create(path.Join(sessionPath, sessionActivateFile)); err == nil {
|
reactivateFile := path.Join(sessionPath, sessionActivateFile)
|
||||||
|
if f, err := os.Create(reactivateFile); err == nil {
|
||||||
f.Close()
|
f.Close()
|
||||||
}
|
}
|
||||||
return nil, ErrAnotherInstance
|
time.Sleep(750 * time.Millisecond)
|
||||||
|
if _, err := os.Stat(reactivateFile); err == nil {
|
||||||
|
log.Println("No other instance responded. Starting as normal...")
|
||||||
|
os.RemoveAll(sessionPath)
|
||||||
|
} else {
|
||||||
|
return nil, ErrAnotherInstance
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Starting %s...", appName)
|
log.Printf("Starting %s...", appName)
|
||||||
|
|||||||
Reference in New Issue
Block a user