From 09f3b8c05fc6765d73544b841b597483543c8891 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Mon, 10 Mar 2025 16:24:18 -0400 Subject: [PATCH] setup: Add seeds and no server feature We will want both of these for most clustered setups. --- cli/util/args.go | 11 +++++++---- setup/svc.go | 25 ++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/cli/util/args.go b/cli/util/args.go index 1fcc1951..6c9375d6 100644 --- a/cli/util/args.go +++ b/cli/util/args.go @@ -163,10 +163,13 @@ type SetupPkgArgs struct { // SetupSvcArgs is the setup service CLI parsing structure and type of the // parsed result. type SetupSvcArgs struct { - BinaryPath string `arg:"--binary-path" help:"path to the binary"` - Install bool `arg:"--install" help:"install the systemd mgmt service"` - Start bool `arg:"--start" help:"start the mgmt service"` - Enable bool `arg:"--enable" help:"enable the mgmt service"` + BinaryPath string `arg:"--binary-path" help:"path to the binary"` + Seeds []string `arg:"--seeds,env:MGMT_SEEDS" help:"default etcd client endpoints"` + NoServer bool `arg:"--no-server" help:"do not start embedded etcd server (do not promote from client to peer)"` + + Install bool `arg:"--install" help:"install the systemd mgmt service"` + Start bool `arg:"--start" help:"start the mgmt service"` + Enable bool `arg:"--enable" help:"enable the mgmt service"` } // SetupFirstbootArgs is the setup service CLI parsing structure and type of the diff --git a/setup/svc.go b/setup/svc.go index f00c8037..bbbf3675 100644 --- a/setup/svc.go +++ b/setup/svc.go @@ -33,6 +33,7 @@ import ( "context" "fmt" "os" + "strings" cliUtil "github.com/purpleidea/mgmt/cli/util" "github.com/purpleidea/mgmt/util" @@ -93,16 +94,38 @@ func (obj *Svc) Run(ctx context.Context) error { Logf: obj.Logf, } + if obj.SetupSvcArgs.NoServer && len(obj.SetupSvcArgs.Seeds) == 0 { + return fmt.Errorf("--no-server can't be used with zero seeds") + } + if obj.SetupSvcArgs.Install { binaryPath := "/usr/bin/mgmt" // default if s := obj.SetupSvcArgs.BinaryPath; s != "" { binaryPath = s } + argv := []string{ + binaryPath, + "run", // run command + } + + if seeds := obj.SetupSvcArgs.Seeds; len(seeds) > 0 { + // TODO: validate each seed? + s := fmt.Sprintf("--seeds=%s", strings.Join(seeds, ",")) + argv = append(argv, s) + } + + if obj.SetupSvcArgs.NoServer { + argv = append(argv, "--no-server") + } + + argv = append(argv, "empty $OPTS") + execStart := strings.Join(argv, " ") + unit := &util.UnitData{ Description: "Mgmt configuration management service", Documentation: "https://github.com/purpleidea/mgmt/", - ExecStart: fmt.Sprintf("%s run empty $OPTS", binaryPath), + ExecStart: execStart, RestartSec: "5s", Restart: "always", WantedBy: []string{"multi-user.target"},