2021-06-20 23:01:44 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/kardianos/service"
|
2021-08-17 09:14:21 +02:00
|
|
|
log "github.com/sirupsen/logrus"
|
2021-06-20 23:01:44 +02:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (p *program) Start(s service.Service) error {
|
|
|
|
// Start should not block. Do the actual work async.
|
2021-08-17 09:14:21 +02:00
|
|
|
log.Info("starting service") //nolint
|
2021-08-18 13:35:42 +02:00
|
|
|
go func() {
|
|
|
|
err := upCmd.RunE(p.cmd, p.args)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
}()
|
2021-06-20 23:01:44 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *program) Stop(s service.Service) error {
|
2021-07-17 14:38:59 +02:00
|
|
|
stopCh <- 1
|
2021-06-20 23:01:44 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
runCmd = &cobra.Command{
|
|
|
|
Use: "run",
|
|
|
|
Short: "runs wiretrustee as service",
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
|
|
|
|
prg := &program{
|
|
|
|
cmd: cmd,
|
|
|
|
args: args,
|
|
|
|
}
|
|
|
|
|
|
|
|
s, err := newSVC(prg, newSVCConfig())
|
|
|
|
if err != nil {
|
2021-06-22 01:07:12 +02:00
|
|
|
cmd.PrintErrln(err)
|
|
|
|
return
|
2021-06-20 23:01:44 +02:00
|
|
|
}
|
|
|
|
err = s.Run()
|
|
|
|
if err != nil {
|
2021-06-22 01:07:12 +02:00
|
|
|
cmd.PrintErrln(err)
|
|
|
|
return
|
2021-06-20 23:01:44 +02:00
|
|
|
}
|
2021-06-22 01:07:12 +02:00
|
|
|
cmd.Printf("Wiretrustee service is running")
|
2021-06-20 23:01:44 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
startCmd = &cobra.Command{
|
|
|
|
Use: "start",
|
|
|
|
Short: "starts wiretrustee service",
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
|
|
|
|
s, err := newSVC(&program{}, newSVCConfig())
|
|
|
|
if err != nil {
|
2021-06-22 01:07:12 +02:00
|
|
|
cmd.PrintErrln(err)
|
|
|
|
return
|
2021-06-20 23:01:44 +02:00
|
|
|
}
|
|
|
|
err = s.Start()
|
|
|
|
if err != nil {
|
2021-06-22 01:07:12 +02:00
|
|
|
cmd.PrintErrln(err)
|
|
|
|
return
|
2021-06-20 23:01:44 +02:00
|
|
|
}
|
2021-06-22 01:07:12 +02:00
|
|
|
cmd.Printf("Wiretrustee service has been started")
|
2021-06-20 23:01:44 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
stopCmd = &cobra.Command{
|
|
|
|
Use: "stop",
|
|
|
|
Short: "stops wiretrustee service",
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
|
|
|
|
s, err := newSVC(&program{}, newSVCConfig())
|
|
|
|
if err != nil {
|
2021-06-22 01:07:12 +02:00
|
|
|
cmd.PrintErrln(err)
|
|
|
|
return
|
2021-06-20 23:01:44 +02:00
|
|
|
}
|
|
|
|
err = s.Stop()
|
|
|
|
if err != nil {
|
2021-06-22 01:07:12 +02:00
|
|
|
cmd.PrintErrln(err)
|
|
|
|
return
|
2021-06-20 23:01:44 +02:00
|
|
|
}
|
2021-06-22 01:07:12 +02:00
|
|
|
cmd.Printf("Wiretrustee service has been stopped")
|
2021-06-20 23:01:44 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
restartCmd = &cobra.Command{
|
|
|
|
Use: "restart",
|
|
|
|
Short: "restarts wiretrustee service",
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
|
|
|
|
s, err := newSVC(&program{}, newSVCConfig())
|
|
|
|
if err != nil {
|
2021-06-22 01:07:12 +02:00
|
|
|
cmd.PrintErrln(err)
|
|
|
|
return
|
2021-06-20 23:01:44 +02:00
|
|
|
}
|
|
|
|
err = s.Restart()
|
|
|
|
if err != nil {
|
2021-06-22 01:07:12 +02:00
|
|
|
cmd.PrintErrln(err)
|
|
|
|
return
|
2021-06-20 23:01:44 +02:00
|
|
|
}
|
2021-06-22 01:07:12 +02:00
|
|
|
cmd.Printf("Wiretrustee service has been restarted")
|
2021-06-20 23:01:44 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
}
|