diff --git a/wavesrv/cmd/main-server.go b/wavesrv/cmd/main-server.go index 4fe9e5951..38b9a87bb 100644 --- a/wavesrv/cmd/main-server.go +++ b/wavesrv/cmd/main-server.go @@ -18,6 +18,7 @@ import ( "os/signal" "path/filepath" "regexp" + "runtime" "runtime/debug" "strconv" "strings" @@ -793,7 +794,7 @@ func main() { scLock, err := scbase.AcquireWaveLock() if err != nil || scLock == nil { - log.Printf("[error] cannot acquire wave lock: %v\n", err) + log.Printf("[error] cannot acquire wave lock (another instance of wavesrv is likely running): %v\n", err) return } if len(os.Args) >= 2 && strings.HasPrefix(os.Args[1], "--migrate") { @@ -886,4 +887,5 @@ func main() { if err != nil { log.Printf("ERROR: %v\n", err) } + runtime.KeepAlive(scLock) } diff --git a/wavesrv/pkg/scbase/scbase.go b/wavesrv/pkg/scbase/scbase.go index 444bae64f..c47bcb2ce 100644 --- a/wavesrv/pkg/scbase/scbase.go +++ b/wavesrv/pkg/scbase/scbase.go @@ -156,7 +156,8 @@ func AcquireWaveLock() (*os.File, error) { return nil, fmt.Errorf("cannot find/create WAVETERM_HOME directory %q", homeDir) } lockFileName := path.Join(homeDir, WaveLockFile) - fd, err := os.OpenFile(lockFileName, os.O_WRONLY|os.O_CREATE, 0600) + log.Printf("[base] acquiring lock on %s\n", lockFileName) + fd, err := os.OpenFile(lockFileName, os.O_RDWR|os.O_CREATE, 0600) if err != nil { return nil, err }