本文整理汇总了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
}
示例2: uninstallService
func uninstallService(s service.Service) {
err := s.Uninstall()
if err != nil {
log.Println(err)
} else {
log.Println("IPSecDiagTool Daemon successfully uninstalled.")
}
}
示例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
}
示例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
}
}
示例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,
})
}
}
}
示例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
}