netbird/client/cmd/service_controller.go
Mikhail Bragin 1dfa99d07c
add wiretrustee LOGIN command (#90)
* feature: add wiretrustee LOGIN command

* chore: add management initial connection timeout

* test: add login cmd test

* test: validate generated config in login cmd

* test: add up command test

* chore: add timeout to signal client creation method

* test: close wireguard interface once test finished
2021-08-18 13:35:42 +02:00

118 lines
2.0 KiB
Go

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.
log.Info("starting service") //nolint
go func() {
err := upCmd.RunE(p.cmd, p.args)
if err != nil {
return
}
}()
return nil
}
func (p *program) Stop(s service.Service) error {
stopCh <- 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 {
cmd.PrintErrln(err)
return
}
err = s.Run()
if err != nil {
cmd.PrintErrln(err)
return
}
cmd.Printf("Wiretrustee service is running")
},
}
)
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 {
cmd.PrintErrln(err)
return
}
err = s.Start()
if err != nil {
cmd.PrintErrln(err)
return
}
cmd.Printf("Wiretrustee service has been started")
},
}
)
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 {
cmd.PrintErrln(err)
return
}
err = s.Stop()
if err != nil {
cmd.PrintErrln(err)
return
}
cmd.Printf("Wiretrustee service has been stopped")
},
}
)
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 {
cmd.PrintErrln(err)
return
}
err = s.Restart()
if err != nil {
cmd.PrintErrln(err)
return
}
cmd.Printf("Wiretrustee service has been restarted")
},
}
)
func init() {
}