signal.go 403 B

12345678910111213141516171819202122232425
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package utils
  4. import (
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. "time"
  9. )
  10. var ExitRecieved bool
  11. func HandleExitSignal() {
  12. sigs := make(chan os.Signal, 1)
  13. signal.Notify(sigs, syscall.SIGTERM)
  14. go func() {
  15. <-sigs
  16. ExitRecieved = true
  17. t := time.NewTimer(5 * time.Second)
  18. <-t.C
  19. os.Exit(0)
  20. }()
  21. }