2021-06-19 14:55:45 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2022-03-08 14:47:55 +01:00
|
|
|
"context"
|
2024-09-02 23:46:36 +02:00
|
|
|
|
2021-06-19 14:55:45 +02:00
|
|
|
"github.com/kardianos/service"
|
2021-06-20 23:01:44 +02:00
|
|
|
log "github.com/sirupsen/logrus"
|
2021-06-19 14:55:45 +02:00
|
|
|
"github.com/spf13/cobra"
|
2022-03-08 14:47:55 +01:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
2022-03-26 12:08:54 +01:00
|
|
|
"github.com/netbirdio/netbird/client/internal"
|
2024-09-02 23:46:36 +02:00
|
|
|
"github.com/netbirdio/netbird/client/server"
|
2021-06-19 14:55:45 +02:00
|
|
|
)
|
|
|
|
|
2021-06-20 23:01:44 +02:00
|
|
|
type program struct {
|
2024-09-02 23:46:36 +02:00
|
|
|
ctx context.Context
|
|
|
|
cancel context.CancelFunc
|
|
|
|
serv *grpc.Server
|
|
|
|
serverInstance *server.Server
|
2022-03-08 14:47:55 +01:00
|
|
|
}
|
|
|
|
|
2022-03-25 13:21:04 +01:00
|
|
|
func newProgram(ctx context.Context, cancel context.CancelFunc) *program {
|
|
|
|
ctx = internal.CtxInitState(ctx)
|
|
|
|
return &program{ctx: ctx, cancel: cancel}
|
2021-06-20 23:01:44 +02:00
|
|
|
}
|
|
|
|
|
2021-06-19 14:55:45 +02:00
|
|
|
func newSVCConfig() *service.Config {
|
|
|
|
return &service.Config{
|
2024-03-12 18:29:19 +01:00
|
|
|
Name: serviceName,
|
2022-05-22 18:53:47 +02:00
|
|
|
DisplayName: "Netbird",
|
2021-06-23 01:06:47 +02:00
|
|
|
Description: "A WireGuard-based mesh network that connects your devices into a single private network.",
|
2022-11-23 13:39:42 +01:00
|
|
|
Option: make(service.KeyValue),
|
2021-06-19 14:55:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-20 23:01:44 +02:00
|
|
|
func newSVC(prg *program, conf *service.Config) (service.Service, error) {
|
|
|
|
s, err := service.New(prg, conf)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return s, nil
|
|
|
|
}
|
|
|
|
|
2022-03-08 14:47:55 +01:00
|
|
|
var serviceCmd = &cobra.Command{
|
|
|
|
Use: "service",
|
2022-05-22 18:53:47 +02:00
|
|
|
Short: "manages Netbird service",
|
2022-03-08 14:47:55 +01:00
|
|
|
}
|