Move the supported systemd path to two services: an owner-user bangerd for orchestration and a narrow root helper for bridge/tap, NAT/resolver, dm/loop, and Firecracker ownership. This removes repeated sudo from daily vm and image flows without leaving the general daemon running as root. Add install metadata, system install/status/restart/uninstall commands, and a system-owned runtime layout. Keep user SSH/config material in the owner home, lock file_sync to the owner home, and move daemon known_hosts handling out of the old root-owned control path. Route privileged lifecycle steps through typed privilegedOps calls, harden the two systemd units, and rewrite smoke plus docs around the supported service model. Verified with make build, make test, make lint, and make smoke on the supported systemd host path.
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package cli
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"banger/internal/daemon"
|
|
"banger/internal/roothelper"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func NewBangerdCommand() *cobra.Command {
|
|
var systemMode bool
|
|
var rootHelperMode bool
|
|
cmd := &cobra.Command{
|
|
Use: "bangerd",
|
|
Short: "Run the banger daemon",
|
|
SilenceUsage: true,
|
|
SilenceErrors: true,
|
|
Args: noArgsUsage("usage: bangerd"),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
if systemMode && rootHelperMode {
|
|
return errors.New("choose only one of --system or --root-helper")
|
|
}
|
|
if rootHelperMode {
|
|
server, err := roothelper.Open()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer server.Close()
|
|
return server.Serve(cmd.Context())
|
|
}
|
|
open := daemon.Open
|
|
if systemMode {
|
|
open = daemon.OpenSystem
|
|
}
|
|
d, err := open(cmd.Context())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer d.Close()
|
|
return d.Serve(cmd.Context())
|
|
},
|
|
}
|
|
cmd.Flags().BoolVar(&systemMode, "system", false, "run as the owner-user system service")
|
|
cmd.Flags().BoolVar(&rootHelperMode, "root-helper", false, "run as the privileged root helper service")
|
|
cmd.CompletionOptions.DisableDefaultCmd = true
|
|
return cmd
|
|
}
|