service

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package service installs bubbles as an operating-system service: a Windows service (SCM), a macOS LaunchDaemon or a Linux systemd unit.

Everything that executes a command goes through an injectable Runner and every file write through Options, so unit tests assert the exact rendered unit, plist and command lines without touching the host. The render and command-list functions are pure and compiled on every platform.

Index

Constants

View Source
const (
	FirewallHTTPSRule      = "bubbles HTTPS"
	FirewallOnboardingRule = "bubbles onboarding"
)

Firewall rule names. Only the private profile is opened: bubbles serves private networks only.

View Source
const (
	WindowsServiceName = "bubbles"
	LaunchdLabel       = "com.bubbles.server"
	LaunchdPlistPath   = "/Library/LaunchDaemons/com.bubbles.server.plist"
	SystemdUnitName    = "bubbles.service"
	SystemdUnitPath    = "/etc/systemd/system/bubbles.service"
	LinuxUser          = "bubbles"
)

Names of the installed service on each platform.

View Source
const LaunchdLogPath = "/var/log/bubbles.log"

LaunchdLogPath receives the daemon's stdout and stderr.

Variables

View Source
var (
	LaunchdBootstrap = []string{"launchctl", "bootstrap", "system", LaunchdPlistPath}
	LaunchdBootout   = []string{"launchctl", "bootout", launchdTarget}
	LaunchdKickstart = []string{"launchctl", "kickstart", "-k", launchdTarget}
	LaunchdPrint     = []string{"launchctl", "print", launchdTarget}
)

Launchd command lines.

View Source
var ErrNotAdmin = errors.New("installing a service requires administrator privileges: run as root (sudo) or from an elevated prompt")

ErrNotAdmin means the process lacks the privileges to manage the service.

View Source
var ErrUnsupported = errors.New("service management is not supported on this platform")

ErrUnsupported is returned on platforms without a service manager integration.

Functions

func FirewallAddCommands

func FirewallAddCommands(httpsPort, httpPort int) [][]string

FirewallAddCommands returns the netsh commands that open the HTTPS and onboarding ports for inbound traffic on the private profile.

func FirewallDeleteCommands

func FirewallDeleteCommands() [][]string

FirewallDeleteCommands removes the rules added by FirewallAddCommands.

func IsWindowsService

func IsWindowsService() bool

IsWindowsService reports whether the process was started by the Windows SCM.

func RenderLaunchdPlist

func RenderLaunchdPlist(s Spec) string

RenderLaunchdPlist renders /Library/LaunchDaemons/com.bubbles.server.plist. It is kept identical to deploy/launchd/com.bubbles.server.plist for the default spec.

func RenderSystemdUnit

func RenderSystemdUnit(s Spec) (string, error)

RenderSystemdUnit renders /etc/systemd/system/bubbles.service. It is kept identical to deploy/systemd/bubbles.service for the default spec.

func RunAsService

func RunAsService(run func(ctx context.Context) int) error

RunAsService is only meaningful on Windows.

func SystemdInstallCommands

func SystemdInstallCommands() [][]string

SystemdInstallCommands are run after the unit file is written, in order.

func SystemdPrepareCommands

func SystemdPrepareCommands(s Spec, userExists bool) [][]string

SystemdPrepareCommands create the service user (when missing) and the data directory owned by it. userExists tells whether `id -u bubbles` succeeded.

Types

type ExecRunner

type ExecRunner struct{}

ExecRunner runs real commands.

func (ExecRunner) Run

func (ExecRunner) Run(ctx context.Context, name string, args ...string) (string, error)

Run implements Runner.

type Manager

type Manager interface {
	Install(ctx context.Context, spec Spec) error
	Uninstall(ctx context.Context) error
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
	// Status returns a short human-readable state such as "active" or "running".
	Status(ctx context.Context) (string, error)
}

Manager controls the installed service.

func New

func New(opts Options) Manager

New returns the Manager for the running platform.

type Options

type Options struct {
	Runner    Runner
	IsAdmin   func() bool
	WriteFile func(path string, data []byte, mode os.FileMode) error
	Remove    func(path string) error
}

Options injects the side effects of a Manager.

type Runner

type Runner interface {
	Run(ctx context.Context, name string, args ...string) (string, error)
}

Runner executes an external command and returns its combined output.

type Spec

type Spec struct {
	// Exe is the absolute path of the bubbles binary.
	Exe string
	// DataDir is the service data directory.
	DataDir string
	// HTTPSAddr and HTTPAddr are passed to serve only when they differ from
	// the defaults; they also decide the firewall ports.
	HTTPSAddr string
	HTTPAddr  string
}

Spec describes the service to install.

func DefaultSpec

func DefaultSpec() (Spec, error)

DefaultSpec returns the spec for the running binary with the platform's service data directory.

func (Spec) Ports

func (s Spec) Ports() (https, http int, err error)

Ports returns the HTTPS and onboarding (HTTP) TCP ports.

func (Spec) ServeArgs

func (s Spec) ServeArgs() []string

ServeArgs returns the argument list that starts the server for this spec.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL