1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package main
- import (
- "datasync/kpt"
- "os"
- "time"
- "github.com/kardianos/service"
- )
- 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
- }
- }
- // kpt.Mq_ConsumerXxw(context.Background())
- // kpt.Mq_Consumer(context.Background())
- kpt.Kafka_Consumer()
- Ch := make(chan int, 1)
- <-Ch
- //
- // _ = s.Run()
- }
|