Add service controllers and installers commands

This commit is contained in:
mlsmaycon
2021-06-20 23:01:44 +02:00
parent 06c7af058b
commit a66cdccda9
5 changed files with 196 additions and 63 deletions

99
cmd/service_controller.go Normal file
View File

@@ -0,0 +1,99 @@
package cmd
import (
"github.com/kardianos/service"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func (p *program) Start(s service.Service) error {
// Start should not block. Do the actual work async.
logger.Info("Starting service") //nolint
go upCmd.Run(p.cmd, p.args)
return nil
}
func (p *program) Stop(s service.Service) error {
stopUP <- 1
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 {
log.Fatal(err)
}
err = s.Run()
if err != nil {
logger.Error(err) //nolint
}
},
}
)
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 {
log.Fatal(err)
}
err = s.Start()
if err != nil {
logger.Error(err) //nolint
}
},
}
)
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 {
log.Fatal(err)
}
err = s.Stop()
if err != nil {
logger.Error(err) //nolint
}
},
}
)
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 {
log.Fatal(err)
}
err = s.Restart()
if err != nil {
logger.Error(err) //nolint
}
},
}
)
func init() {
}