1
0

main.go 636 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/snail007/goproxy/services"
  5. "log"
  6. "os"
  7. "os/signal"
  8. "syscall"
  9. )
  10. const APP_VERSION = "3.0"
  11. func main() {
  12. err := initConfig()
  13. if err != nil {
  14. log.Fatalf("err : %s", err)
  15. }
  16. Clean(&service.S)
  17. }
  18. func Clean(s *services.Service) {
  19. signalChan := make(chan os.Signal, 1)
  20. cleanupDone := make(chan bool)
  21. signal.Notify(signalChan,
  22. os.Interrupt,
  23. syscall.SIGHUP,
  24. syscall.SIGINT,
  25. syscall.SIGTERM,
  26. syscall.SIGQUIT)
  27. go func() {
  28. for _ = range signalChan {
  29. fmt.Println("\nReceived an interrupt, stopping services...")
  30. (*s).Clean()
  31. cleanupDone <- true
  32. }
  33. }()
  34. <-cleanupDone
  35. }