service
service copied to clipboard
Could not start service with promptui
Hi,
I get the error when trying to run my service code on windows :
`The service did not respond to the start or control request in a timely fashion.`
I have taken a look on this https://github.com/kardianos/service/issues/166 but no help.
My code looks like below (a very simple logic). If try to remove promptui related code with a little change to get arguments from command line, let the executable run with command "myapp install", the service could run up successfully. Could somebody help to figure out what is wrong?
Thanks
package main
import (
"fmt"
"github.com/kardianos/service"
"github.com/manifoldco/promptui"
)
// Program structures.
// Define Start and Stop methods.
type program struct{}
func (p *program) Start(s service.Service) error {
go p.run()
return nil
}
func (p *program) run() {
myservice()
}
func (p *program) Stop(s service.Service) error {
return nil
}
func main() {
prompt := promptui.Select{
Label: "Options",
Items: []string{"install", "start", "stop", "uninstall"},
}
_, result, err := prompt.Run()
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
return
}
fmt.Printf("You choose %q\n", result)
ServiceArg := make([]string, 1)
ServiceArg[0] = result
var sc = &service.Config{
Name: "test",
DisplayName: "test",
Description: "test",
Arguments: ServiceArg,
}
prg := &program{}
s, err := service.New(prg, sc)
if err != nil {
}
switch result {
case "install":
err = s.Install()
if err != nil {
fmt.Println(err)
break
}
fmt.Println("install done, try to start")
err = s.Start()
if err != nil {
fmt.Println(err)
break
}
case "start":
err = s.Start()
if err != nil {
fmt.Println(err)
break
}
case "stop":
err = s.Stop()
if err != nil {
fmt.Println(err)
break
}
case "uninstall":
err = s.Stop()
err = s.Uninstall()
if err != nil {
fmt.Println(err)
break
}
fmt.Println("uninstall done")
default:
err = s.Run()
if err != nil {
fmt.Println(err)
break
}
}
}