restart server when crashed

Related #65
This commit is contained in:
Gokcehan 2018-06-05 22:11:20 +03:00
parent 397d5e0fac
commit 448f2a3cb2

21
main.go
View File

@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"log"
"net"
"os"
"os/exec"
"path/filepath"
@ -42,6 +43,21 @@ func startServer() {
}
}
func checkServer() {
if gSocketProt == "unix" {
if _, err := os.Stat(gSocketPath); os.IsNotExist(err) {
startServer()
} else if _, err := net.Dial(gSocketProt, gSocketPath); err != nil {
os.Remove(gSocketPath)
startServer()
}
} else {
if _, err := net.Dial(gSocketProt, gSocketPath); err != nil {
startServer()
}
}
}
func main() {
showDoc := flag.Bool(
"doc",
@ -125,10 +141,7 @@ func main() {
gServerLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.server.log", gUser.Username))
serve()
default:
// TODO: check if the socket is working
if _, err := os.Stat(gSocketPath); os.IsNotExist(err) {
startServer()
}
checkServer()
gClientID = 1000
gLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.%d.log", gUser.Username, gClientID))