setup: Add seeds and no server feature

We will want both of these for most clustered setups.
This commit is contained in:
James Shubin
2025-03-10 16:24:18 -04:00
parent f5e2fde20d
commit 09f3b8c05f
2 changed files with 31 additions and 5 deletions

View File

@@ -164,6 +164,9 @@ type SetupPkgArgs struct {
// parsed result. // parsed result.
type SetupSvcArgs struct { type SetupSvcArgs struct {
BinaryPath string `arg:"--binary-path" help:"path to the binary"` 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"` Install bool `arg:"--install" help:"install the systemd mgmt service"`
Start bool `arg:"--start" help:"start the mgmt service"` Start bool `arg:"--start" help:"start the mgmt service"`
Enable bool `arg:"--enable" help:"enable the mgmt service"` Enable bool `arg:"--enable" help:"enable the mgmt service"`

View File

@@ -33,6 +33,7 @@ import (
"context" "context"
"fmt" "fmt"
"os" "os"
"strings"
cliUtil "github.com/purpleidea/mgmt/cli/util" cliUtil "github.com/purpleidea/mgmt/cli/util"
"github.com/purpleidea/mgmt/util" "github.com/purpleidea/mgmt/util"
@@ -93,16 +94,38 @@ func (obj *Svc) Run(ctx context.Context) error {
Logf: obj.Logf, 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 { if obj.SetupSvcArgs.Install {
binaryPath := "/usr/bin/mgmt" // default binaryPath := "/usr/bin/mgmt" // default
if s := obj.SetupSvcArgs.BinaryPath; s != "" { if s := obj.SetupSvcArgs.BinaryPath; s != "" {
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{ unit := &util.UnitData{
Description: "Mgmt configuration management service", Description: "Mgmt configuration management service",
Documentation: "https://github.com/purpleidea/mgmt/", Documentation: "https://github.com/purpleidea/mgmt/",
ExecStart: fmt.Sprintf("%s run empty $OPTS", binaryPath), ExecStart: execStart,
RestartSec: "5s", RestartSec: "5s",
Restart: "always", Restart: "always",
WantedBy: []string{"multi-user.target"}, WantedBy: []string{"multi-user.target"},