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
- Variables
- func FirewallAddCommands(httpsPort, httpPort int) [][]string
- func FirewallDeleteCommands() [][]string
- func IsWindowsService() bool
- func RenderLaunchdPlist(s Spec) string
- func RenderSystemdUnit(s Spec) (string, error)
- func RunAsService(run func(ctx context.Context) int) error
- func SystemdInstallCommands() [][]string
- func SystemdPrepareCommands(s Spec, userExists bool) [][]string
- type ExecRunner
- type Manager
- type Options
- type Runner
- type Spec
Constants ¶
const ( FirewallHTTPSRule = "bubbles HTTPS" FirewallOnboardingRule = "bubbles onboarding" )
Firewall rule names. Only the private profile is opened: bubbles serves private networks only.
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.
const LaunchdLogPath = "/var/log/bubbles.log"
LaunchdLogPath receives the daemon's stdout and stderr.
Variables ¶
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.
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.
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 ¶
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 ¶
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 ¶
RenderSystemdUnit renders /etc/systemd/system/bubbles.service. It is kept identical to deploy/systemd/bubbles.service for the default spec.
func RunAsService ¶
RunAsService is only meaningful on Windows.
func SystemdInstallCommands ¶
func SystemdInstallCommands() [][]string
SystemdInstallCommands are run after the unit file is written, in order.
func SystemdPrepareCommands ¶
SystemdPrepareCommands create the service user (when missing) and the data directory owned by it. userExists tells whether `id -u bubbles` succeeded.
Types ¶
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.
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 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
// TailscaleCert passes --tailscale-cert to serve.
TailscaleCert bool
}
Spec describes the service to install.
func DefaultSpec ¶
DefaultSpec returns the spec for the running binary with the platform's service data directory.