123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package main
- import (
- "datasync/kpt"
- "github.com/kardianos/service"
- "os"
- "time"
- )
- type program struct{}
- func (p *program) Start(s service.Service) error {
- go p.run()
- return nil
- }
- func (p *program) run() {
- // 代码写在这儿
- kpt.RunService()
- }
- func (p *program) Stop(s service.Service) error {
- kpt.Ch<-1
- <-time.After(time.Second * 1)
- return nil
- }
- /**
- * MAIN函数,程序入口
- */
- func main() {
- kpt.Readini()
- svcConfig := &service.Config{
- Name: kpt.ServiceName, //服务显示名称
- DisplayName: kpt.ServiceDisplayName, //服务名称
- Description: kpt.ServiceDescription, //服务描述
- Dependencies: []string{"TMRWatchDB"},
- }
- prg := &program{}
- s, _ := service.New(prg, svcConfig)
- if len(os.Args) > 1 {
- if os.Args[1] == "install" {
- s.Install()
- return
- }
- if os.Args[1] == "remove" {
- s.Uninstall()
- return
- }
- }
- _ = s.Run()
- }
|