main.go 889 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package main
  2. import (
  3. "datasync/kpt"
  4. "github.com/kardianos/service"
  5. "os"
  6. "time"
  7. )
  8. type program struct{}
  9. func (p *program) Start(s service.Service) error {
  10. go p.run()
  11. return nil
  12. }
  13. func (p *program) run() {
  14. // 代码写在这儿
  15. kpt.RunService()
  16. }
  17. func (p *program) Stop(s service.Service) error {
  18. kpt.Ch<-1
  19. <-time.After(time.Second * 1)
  20. return nil
  21. }
  22. /**
  23. * MAIN函数,程序入口
  24. */
  25. func main() {
  26. kpt.Readini()
  27. svcConfig := &service.Config{
  28. Name: kpt.ServiceName, //服务显示名称
  29. DisplayName: kpt.ServiceDisplayName, //服务名称
  30. Description: kpt.ServiceDescription, //服务描述
  31. Dependencies: []string{"TMRWatchDB"},
  32. }
  33. prg := &program{}
  34. s, _ := service.New(prg, svcConfig)
  35. if len(os.Args) > 1 {
  36. if os.Args[1] == "install" {
  37. s.Install()
  38. return
  39. }
  40. if os.Args[1] == "remove" {
  41. s.Uninstall()
  42. return
  43. }
  44. }
  45. _ = s.Run()
  46. }