mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-25 17:43:38 +01:00
4587f7686e
* feat: basic management service implementation [FAILING TESTS] * test: fix healthcheck test * test: #39 add peer registration endpoint test * feat: #39 add setup key handling * feat: #39 add peer management store persistence * refactor: extract config read/write to the utility package * refactor: move file contents copy to the utility package * refactor: use Accounts instead of Users in the Store * feature: add management server Docker file * refactor: introduce datadir instead of config * chore: use filepath.Join to concat filepaths instead of string concat * refactor: move stop channel to the root * refactor: move stop channel to the root * review: fix PR review notes Co-authored-by: braginini <hello@wiretrustee.com>
111 lines
1.9 KiB
Go
111 lines
1.9 KiB
Go
package cmd
|
|
|
|
import (
|
|
"github.com/kardianos/service"
|
|
"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 {
|
|
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() {
|
|
}
|