當前位置: 首頁>>代碼示例>>Golang>>正文


Golang service.Service類代碼示例

本文整理匯總了Golang中github.com/kardianos/service.Service的典型用法代碼示例。如果您正苦於以下問題:Golang Service類的具體用法?Golang Service怎麽用?Golang Service使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Service類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: run

func run(s service.Service, m *supervisorgo.Manager, u *url.URL) int {
	var err error
	var l net.Listener
	path := jsonrpc.DefaultRPCPath
	switch u.Scheme {
	case "unix":
		l, err = net.Listen(u.Scheme, u.Opaque+u.Path)
		if l != nil {
			defer os.Remove(u.Opaque + u.Path)
		}
	case "http":
		l, err = net.Listen("tcp", u.Host)
		path = u.Path
	default:
		err = fmt.Errorf("not supported scheme: %s", u.Scheme)
	}
	if err != nil {
		log.Println(err)
		return 1
	}
	m.HTTPServe(path)
	go http.Serve(l, nil)

	err = s.Run()
	if err != nil {
		log.Println(err)
		return 1
	}
	return 0
}
開發者ID:insionng,項目名稱:supervisorgo,代碼行數:30,代碼來源:main.go

示例2: uninstallService

func uninstallService(s service.Service) {
	err := s.Uninstall()
	if err != nil {
		log.Println(err)
	} else {
		log.Println("IPSecDiagTool Daemon successfully uninstalled.")
	}
}
開發者ID:mehulsbhatt,項目名稱:ipsecdiagtool,代碼行數:8,代碼來源:main.go

示例3: Start

func (p *program) Start(s service.Service) error {
	msg := fmt.Sprintf("Service '%s' started.", serviceName())
	logger.Printf(msg)
	sysLogger, err := s.Logger(nil)
	if err != nil {
		sysLogger.Info(msg)
	}

	doStart()

	go watchForReload()
	return nil
}
開發者ID:Joffcom,項目名稱:silver,代碼行數:13,代碼來源:main.go

示例4: runHttp

func (p *program) runHttp(s service.Service) {
	var cmds []string = []string{"shut", "reboot"}
	for index, command := range cmds {
		http.HandleFunc(fmt.Sprintf("/%s", command), handleFunc(index, command))
	}
	logger.Info("http server start ...")
	err := http.ListenAndServe(":7070", nil)
	if err != nil {
		logger.Error(err)
		s.Stop()
		return
	}
}
開發者ID:kyf,項目名稱:shuthelper_server,代碼行數:13,代碼來源:main.go

示例5: runUDP

func (p *program) runUDP(s service.Service) {
	localAddr := getLocalAddr()
	if localAddr == nil {
		s.Stop()
		return
	}
	socket, err := net.ListenUDP("udp4", &net.UDPAddr{
		IP:   net.IPv4(0, 0, 0, 0),
		Port: 6060,
	})
	if err != nil {
		logger.Error(err)
		s.Stop()
		return
	}

	logger.Info("udp server has start ...")
	defer socket.Close()
	out := make([]byte, 1024)
	for {
		select {
		case <-exit:
			return
		default:
			_, addr, err := socket.ReadFromUDP(out)
			if err != nil {
				logger.Error(err)
				continue
			}
			//logger.Infof("receive [%v] data : %s \n", addr.IP, string(out))
			hostname, err := os.Hostname()
			if err != nil {
				logger.Error(err)
				hostname = "unknown"
			}
			resp := map[string]string{
				"ip":       localAddr["IP"],
				"hostname": hostname,
			}
			r, err := json.Marshal(resp)
			if err != nil {
				logger.Error(err)
				continue
			}
			socket.WriteToUDP(r, &net.UDPAddr{
				IP:   addr.IP,
				Port: 6060,
			})
		}
	}
}
開發者ID:kyf,項目名稱:shuthelper_server,代碼行數:51,代碼來源:main.go

示例6: Stop

func (p *program) Stop(s service.Service) error {
	logger.Printf(fmt.Sprintf("Stopping '%s' service...", serviceName()))

	doStop()

	pidFile := config.ServiceConfig.PidFile
	if pidFile != "" {
		os.Remove(pidFile)
	}

	msg := fmt.Sprintf("Stopped '%s' service.", serviceName())
	logger.Printf(msg)

	sysLogger, err := s.Logger(nil)
	if err != nil {
		sysLogger.Info(msg)
	}
	return nil
}
開發者ID:Joffcom,項目名稱:silver,代碼行數:19,代碼來源:main.go


注:本文中的github.com/kardianos/service.Service類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。