service

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package service registers vmflow as a native OS service so it starts at boot and restarts on crash:

  • Linux: systemd unit (/etc/systemd/system/<name>.service)
  • macOS: launchd daemon (/Library/LaunchDaemons/io.cloudapp.<name>.plist)
  • Windows: Windows Service (managed via services.msc / SCM APIs)

The package performs install/start/uninstall/status operations: it generates the unit or plist file and invokes the platform's service manager (systemctl / launchctl / Windows SCM). The runtime itself does not need this package to run: Linux and macOS execute vmflow in the foreground and supervise it via signals; on Windows vmflow detects the SCM at startup (see cmd/vmflow/daemon_windows.go) and reports state itself.

Style follows internal/updater: error-return (no logger in the package), progress streamed to an io.Writer, and file writes use a same-directory temp + rename for atomicity.

Index

Constants

View Source
const DefaultServiceName = "vmflow"

DefaultServiceName is the service/unit/registry name used when Config.Name is empty.

Variables

View Source
var (
	// ErrNotInstalled reports that no native service definition exists.
	ErrNotInstalled = errors.New("native service is not installed")
	// ErrPrivilegesRequired reports that starting the native service requires
	// administrator privileges.
	ErrPrivilegesRequired = errors.New("administrator privileges are required")
)

Functions

func Install

func Install(cfg Config, w io.Writer) error

Install registers, enables, and starts the service.

func Start

func Start(cfg Config, w io.Writer) error

Start starts an existing native service without changing its definition or startup policy. Calling Start for an already-running service succeeds.

func Status

func Status(cfg Config, w io.Writer) error

Status prints the current service status to w.

func Uninstall

func Uninstall(cfg Config, w io.Writer) error

Uninstall stops and removes the service. Config and log files are left in place for the operator to clean up.

Types

type Config

type Config struct {
	// Translator localizes human-readable progress output. It does not affect
	// service names, paths, arguments, templates, or platform state values.
	Translator *i18n.Translator
	// BinaryPath is the vmflow executable path. Defaults to the current
	// executable when empty.
	BinaryPath string
	// ConfigPath is the -config path the service runs with. Defaults to the
	// platform's system config path when empty.
	ConfigPath string
	// ServiceName is the service/unit/registry name. Defaults to "vmflow".
	ServiceName string
	// User is the systemd User= the unit runs as (Linux only). Empty = root.
	// When set and the account is missing, install creates it as a system user.
	User string
	// LogFile redirects daemon logs. On Linux/Windows it is passed to the daemon
	// via -log-file; on macOS it sets the launchd capture paths. Windows defaults
	// to a durable path under ProgramData because the SCM provides no stdout.
	LogFile string
	// ControlPort overrides the daemon's loopback-only management port. Zero
	// keeps the value from the config file.
	ControlPort int
	// ExtraArgs are individual extra arguments appended to the daemon command
	// line for future daemon flags. Existing daemon flags have dedicated Config
	// fields and are rejected here to prevent overriding validated paths.
	ExtraArgs []string
}

Config describes how to install or query the vmflow service.

type InstallPlan

type InstallPlan struct {
	BinaryPath  string
	ConfigPath  string
	ServiceName string
}

InstallPlan is the validated, side-effect-free result of preparing a native service installation. Paths are absolute, symlinks are resolved, and both the binary and config have passed the same trust checks used by Install.

func PlanInstall

func PlanInstall(cfg Config) (InstallPlan, error)

PlanInstall validates a service installation without changing service state. Callers can use it before requesting administrator privileges or presenting an installation plan to a user. Install repeats the validation at commit time.

func PlanInstallTarget

func PlanInstallTarget(cfg Config) (InstallPlan, error)

PlanInstallTarget validates the executable and destination path before an elevated first-run helper creates the system config. It does not require the config file to exist; Install repeats validation against the written file.

type Summary

type Summary struct {
	Installed bool
	Running   bool
	Enabled   bool
	State     string
	Detail    string
}

Summary is a compact, cross-platform native service status.

func Inspect

func Inspect(cfg Config) (Summary, error)

Inspect returns native service state without printing the platform service manager's full diagnostic output.

Jump to

Keyboard shortcuts

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