service.go 977 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (c)2019 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2023-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. /****/
  13. package cli
  14. import (
  15. "fmt"
  16. "os"
  17. "os/signal"
  18. "syscall"
  19. "zerotier/pkg/zerotier"
  20. )
  21. // Service is "zerotier service ..."
  22. func Service(basePath, authToken string, args []string) {
  23. if len(args) > 0 {
  24. Help()
  25. os.Exit(1)
  26. }
  27. node, err := zerotier.NewNode(basePath)
  28. if err != nil {
  29. fmt.Println("FATAL: error initializing node: " + err.Error())
  30. os.Exit(1)
  31. }
  32. osSignalChannel := make(chan os.Signal, 2)
  33. signal.Notify(osSignalChannel, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGINT, syscall.SIGBUS)
  34. signal.Ignore(syscall.SIGUSR1, syscall.SIGUSR2)
  35. <-osSignalChannel
  36. node.Close()
  37. os.Exit(0)
  38. }