main.go 857 B

12345678910111213141516171819202122232425262728293031323334
  1. package main
  2. import (
  3. "context"
  4. "os"
  5. "os/signal"
  6. "sync"
  7. "syscall"
  8. "github.com/gravitl/netmaker/logger"
  9. "github.com/gravitl/netmaker/turnserver/src/controller"
  10. "github.com/gravitl/netmaker/turnserver/src/turn"
  11. )
  12. func main() {
  13. ctx, cancel := context.WithCancel(context.Background())
  14. wg := &sync.WaitGroup{}
  15. // Wait for interrupt signal to gracefully shutdown the server with
  16. // a timeout of 5 seconds.
  17. quit := make(chan os.Signal, 2)
  18. // kill (no param) default send syscanll.SIGTERM
  19. // kill -2 is syscall.SIGINT
  20. // kill -9 is syscall. SIGKILL but cant be caught, so don't need add it
  21. wg.Add(1)
  22. controller.HandleRESTRequests(ctx, wg)
  23. wg.Add(1)
  24. turn.Start(ctx, wg)
  25. signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
  26. <-quit
  27. logger.Log(0, "Recieved Shutdown Signal...")
  28. cancel()
  29. wg.Wait()
  30. logger.Log(0, "Stopping Turn Server...")
  31. }