Skip to content

Commit

Permalink
Merge pull request #468 from Darkren/fix/vpn-server-exit-on-failure
Browse files Browse the repository at this point in the history
Make app exit on VPN server failure
  • Loading branch information
jdknives authored Aug 14, 2020
2 parents c7ae857 + 4789cfe commit fb01f5c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions cmd/apps/vpn-server/vpn-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"os"
"os/signal"
"runtime"
"syscall"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -32,6 +33,10 @@ var (
)

func main() {
if runtime.GOOS != "linux" {
log.Fatalln("OS is not supported")
}

flag.Parse()

localPK := cipher.PubKey{}
Expand Down Expand Up @@ -78,11 +83,19 @@ func main() {
log.WithError(err).Errorln("Error closing server")
}
}()

errCh := make(chan error)
go func() {
if err := srv.Serve(l); err != nil {
log.WithError(err).Errorln("Error serving")
errCh <- err
}

close(errCh)
}()

<-osSigs
select {
case <-osSigs:
case err := <-errCh:
log.WithError(err).Errorln("Error serving")
}
}

0 comments on commit fb01f5c

Please sign in to comment.