Documentation
¶
Overview ¶
Package service installs and controls Mihari as a native OS service.
Index ¶
- Constants
- func DefinitionFileState(file DefinitionFile, link string) string
- func DirectActionHook(ctx context.Context, action DefinitionAction, ...) error
- func IsInteractive() bool
- type ActionHook
- type Clock
- type CommandResult
- type CommandRunner
- type Controller
- type Definition
- type DefinitionAction
- type DefinitionAdapter
- type DefinitionFile
- type DefinitionLink
- type DefinitionStore
- type LaunchdAdapter
- func (a *LaunchdAdapter) BindStopAuthority(def Definition, boot string)
- func (a *LaunchdAdapter) DisableAutostartAndStop(ctx context.Context) error
- func (a *LaunchdAdapter) InspectDefinition(ctx context.Context) (Definition, error)
- func (a *LaunchdAdapter) ObserveAction(ctx context.Context, action DefinitionAction) (string, error)
- func (a *LaunchdAdapter) Probe(ctx context.Context) (Definition, error)
- func (a *LaunchdAdapter) ReplayAction(ctx context.Context, action DefinitionAction) error
- func (a *LaunchdAdapter) RestoreDefinition(ctx context.Context, def Definition) error
- func (a *LaunchdAdapter) Start(ctx context.Context) error
- func (a *LaunchdAdapter) WaitOwnedTreeExit(ctx context.Context) error
- func (a *LaunchdAdapter) WaitRecordedTreeExit(ctx context.Context) error
- func (a *LaunchdAdapter) WriteDefinition(ctx context.Context, def Definition) error
- type LaunchdPaths
- type Manager
- func (m *Manager) Install() error
- func (m *Manager) Reinstall() error
- func (m *Manager) Restart() error
- func (m *Manager) Run() error
- func (m *Manager) Start() error
- func (m *Manager) Status() (StatusKind, error)
- func (m *Manager) Stop() error
- func (m *Manager) Uninstall() error
- func (m *Manager) UpdateInstalledBinary() (bool, error)
- type OSCommandRunner
- type Options
- type ProcessIdentity
- type ProcessTree
- type RecoveryAdapter
- type RunFunc
- type StatusKind
- type SystemdAdapter
- func (a *SystemdAdapter) DisableAutostartAndStop(ctx context.Context) error
- func (a *SystemdAdapter) InspectDefinition(ctx context.Context) (Definition, error)
- func (a *SystemdAdapter) ObserveAction(ctx context.Context, action DefinitionAction) (string, error)
- func (a *SystemdAdapter) Probe(ctx context.Context) (Definition, error)
- func (a *SystemdAdapter) ReplayAction(ctx context.Context, action DefinitionAction) error
- func (a *SystemdAdapter) RestoreDefinition(ctx context.Context, def Definition) error
- func (a *SystemdAdapter) Start(ctx context.Context) error
- func (a *SystemdAdapter) WaitOwnedTreeExit(ctx context.Context) error
- func (a *SystemdAdapter) WriteDefinition(ctx context.Context, def Definition) error
- type SystemdConfig
- type SystemdPaths
Constants ¶
const ( DefinitionActionMask = "mask" DefinitionActionUnmask = "unmask" DefinitionActionDisable = "disable" DefinitionActionEnable = "enable" DefinitionActionStop = "stop" DefinitionActionStart = "start" DefinitionActionDefinition = "definition" DefinitionActionDropin = "dropin" DefinitionActionDisabled = "disabled" DefinitionActionReload = "reload" )
Variables ¶
This section is empty.
Functions ¶
func DefinitionFileState ¶ added in v0.9.3
func DefinitionFileState(file DefinitionFile, link string) string
DefinitionFileState is the content identity recorded before a file action.
func DirectActionHook ¶ added in v0.9.3
func DirectActionHook(ctx context.Context, action DefinitionAction, apply func(context.Context) error) error
DirectActionHook runs apply without journaling. Tests and T14 replace it.
func IsInteractive ¶
func IsInteractive() bool
IsInteractive reports whether this process is running outside the OS service manager. When false (Windows service session), the daemon entrypoint must call Manager.Run so the process registers with SCM (StartServiceCtrlDispatcher).
Types ¶
type ActionHook ¶ added in v0.9.3
type ActionHook func(ctx context.Context, action DefinitionAction, apply func(context.Context) error) error
ActionHook surrounds one concrete manager or filesystem effect. T14 supplies a journaled hook; adapters must call it once per effect.
type CommandResult ¶ added in v0.9.3
CommandResult is a completed process observation. Non-zero ExitCode is not itself an error.
type CommandRunner ¶ added in v0.9.3
type CommandRunner interface {
Run(ctx context.Context, argv []string) (CommandResult, error)
}
CommandRunner executes argv[0] as an absolute path with argv[1:] as arguments.
type Controller ¶
type Controller interface {
Install() error
Uninstall() error
Start() error
Stop() error
Restart() error
Status() (StatusKind, error)
Run() error
}
Controller performs service manager operations (tests inject fakes).
type Definition ¶ added in v0.9.3
type Definition struct {
Status StatusKind
Enabled bool
Running bool
Masked bool
Binary string
Args []string
Env []string
Files []DefinitionFile
Links []DefinitionLink
Process ProcessIdentity
}
Definition is a read-only snapshot of the managed unit or launchd job.
func BuildUnixDefinition ¶ added in v0.9.3
func BuildUnixDefinition(layout platform.ResolvedLayout, goos string) (Definition, error)
BuildUnixDefinition returns the absolute, fixed-environment managed definition.
type DefinitionAction ¶ added in v0.9.3
type DefinitionAction struct {
// Path and File identify a concrete private-backed definition effect.
Path string
File *DefinitionFile
Link string
Kind string
TargetRole string
OldState string
NewState string
}
DefinitionAction is one external mutation T14 wraps with intent/done.
type DefinitionAdapter ¶ added in v0.9.3
type DefinitionAdapter interface {
InspectDefinition(context.Context) (Definition, error)
DisableAutostartAndStop(context.Context) error
WaitOwnedTreeExit(context.Context) error
WriteDefinition(context.Context, Definition) error
RestoreDefinition(context.Context, Definition) error
Start(context.Context) error
Probe(context.Context) (Definition, error)
}
DefinitionAdapter is the Unix service-manager seam consumed by install transactions. Windows keeps Controller and does not implement these methods.
type DefinitionFile ¶ added in v0.9.3
type DefinitionFile struct {
// Identity records the saved inode. Restoration may replace a later unit
// or mask; transaction recovery validates its recorded publication versions.
Identity string
Path string
Bytes []byte
Owner uint32
Mode uint32
Kind string
}
DefinitionFile is one unit, drop-in, mask, or plist object.
type DefinitionLink ¶ added in v0.9.3
DefinitionLink is an enable/wants symlink recorded for exact restore.
type DefinitionStore ¶ added in v0.9.3
type DefinitionStore interface {
Read(ctx context.Context, path string) (DefinitionFile, error)
Write(ctx context.Context, file DefinitionFile) error
Mask(ctx context.Context, path, target string) error
Remove(ctx context.Context, path string) error
ReadLink(ctx context.Context, path string) (string, error)
List(ctx context.Context, dir string) ([]string, error)
}
DefinitionStore reads and publishes service definition objects.
func NewUnixDefinitionStore ¶ added in v0.9.3
func NewUnixDefinitionStore() DefinitionStore
NewUnixDefinitionStore constructs the retained-capability native service store. It performs no IO; each operation verifies and owns its parent capability.
type LaunchdAdapter ¶ added in v0.9.3
type LaunchdAdapter struct {
// contains filtered or unexported fields
}
LaunchdAdapter inspects and mutates the system LaunchDaemon.
func (*LaunchdAdapter) BindStopAuthority ¶ added in v0.9.3
func (a *LaunchdAdapter) BindStopAuthority(def Definition, boot string)
BindStopAuthority retains the private backup's process identity independently of later service-manager observations. It performs no external mutation.
func (*LaunchdAdapter) DisableAutostartAndStop ¶ added in v0.9.3
func (a *LaunchdAdapter) DisableAutostartAndStop(ctx context.Context) error
func (*LaunchdAdapter) InspectDefinition ¶ added in v0.9.3
func (a *LaunchdAdapter) InspectDefinition(ctx context.Context) (Definition, error)
func (*LaunchdAdapter) ObserveAction ¶ added in v0.9.3
func (a *LaunchdAdapter) ObserveAction(ctx context.Context, action DefinitionAction) (string, error)
func (*LaunchdAdapter) Probe ¶ added in v0.9.3
func (a *LaunchdAdapter) Probe(ctx context.Context) (Definition, error)
func (*LaunchdAdapter) ReplayAction ¶ added in v0.9.3
func (a *LaunchdAdapter) ReplayAction(ctx context.Context, action DefinitionAction) error
func (*LaunchdAdapter) RestoreDefinition ¶ added in v0.9.3
func (a *LaunchdAdapter) RestoreDefinition(ctx context.Context, def Definition) error
func (*LaunchdAdapter) Start ¶ added in v0.9.3
func (a *LaunchdAdapter) Start(ctx context.Context) error
func (*LaunchdAdapter) WaitOwnedTreeExit ¶ added in v0.9.3
func (a *LaunchdAdapter) WaitOwnedTreeExit(ctx context.Context) error
func (*LaunchdAdapter) WaitRecordedTreeExit ¶ added in v0.9.3
func (a *LaunchdAdapter) WaitRecordedTreeExit(ctx context.Context) error
WaitRecordedTreeExit checks the private backup's old group before replaying target effects. A newly running target does not change the old group proof.
func (*LaunchdAdapter) WriteDefinition ¶ added in v0.9.3
func (a *LaunchdAdapter) WriteDefinition(ctx context.Context, def Definition) error
type LaunchdPaths ¶ added in v0.9.3
LaunchdPaths is the absolute launchd system-domain layout.
func DefaultLaunchdPaths ¶ added in v0.9.3
func DefaultLaunchdPaths() LaunchdPaths
DefaultLaunchdPaths returns the production LaunchDaemons layout.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is the production entry for service control.
func (*Manager) Install ¶
Install copies mihari into the machine install directory, then registers the OS service with that installed path (never the caller's download location).
func (*Manager) Reinstall ¶
Reinstall stops the service, removes registration, copies this binary into the install directory, re-registers ImagePath, and starts the service.
func (*Manager) Status ¶
func (m *Manager) Status() (StatusKind, error)
Status reports the service state. When the service is not registered, it returns StatusNotInstalled with a nil error so callers (CLI status, TUI badge) can distinguish "not installed" without elevation. On Windows, Access is denied from the default service library falls back to a low-privilege SCM query so non-admin users still see running/stopped/not_installed.
func (*Manager) Uninstall ¶
Uninstall stops the service (if running), then removes the OS service registration. Stopping first avoids Windows SCM "marked for deletion" while the process is still alive.
func (*Manager) UpdateInstalledBinary ¶ added in v0.7.0
UpdateInstalledBinary synchronizes the current executable into the machine install directory and restarts an existing OS service from that copy. It reports whether a service installation was found. A missing service is a successful no-op.
type OSCommandRunner ¶ added in v0.9.3
type OSCommandRunner struct{}
OSCommandRunner invokes an absolute executable without a shell.
func (OSCommandRunner) Run ¶ added in v0.9.3
func (OSCommandRunner) Run(ctx context.Context, argv []string) (CommandResult, error)
type Options ¶
type Options struct {
// Executable is the absolute path to mihari. Empty uses the current process executable.
Executable string
// Arguments defaults to ["daemon"].
Arguments []string
// Run is required only for Run().
Run RunFunc
// Ready is closed by the daemon body when the control plane is listening.
// When non-nil, program.Start waits for it (or run exit / timeout) before returning.
Ready <-chan struct{}
// StartTimeout bounds how long Start waits for Ready. Zero means 15s.
StartTimeout time.Duration
// NewController builds a Controller; tests replace it.
NewController func(run RunFunc, executable string, arguments []string) (Controller, error)
}
Options configures which binary the OS service should launch.
type ProcessIdentity ¶ added in v0.9.3
type ProcessIdentity struct {
PID int
BootID string
StartUnix int64
StartUsec uint32
Group string
Comm string
}
ProcessIdentity identifies a managed process across PID reuse.
func RecordedLaunchdIdentity ¶ added in v0.9.3
func RecordedLaunchdIdentity(boot string, pid int, start string) (ProcessIdentity, error)
RecordedLaunchdIdentity reconstructs a query-only group identity from a protected runtime generation. It never authorizes signaling a historic PID.
type ProcessTree ¶ added in v0.9.3
type ProcessTree interface {
Empty(ctx context.Context, group string) (bool, error)
SignalGroup(ctx context.Context, group, signal string) error
Lookup(ctx context.Context, id ProcessIdentity) (bool, error)
SignalIdentity(ctx context.Context, id ProcessIdentity, signal string) error
Identify(ctx context.Context, pid int) (ProcessIdentity, error)
}
ProcessTree observes and signals a verified cgroup or launchd identity.
type RecoveryAdapter ¶ added in v0.9.3
type RecoveryAdapter interface {
DefinitionAdapter
ObserveAction(context.Context, DefinitionAction) (string, error)
ReplayAction(context.Context, DefinitionAction) error
}
RecoveryAdapter performs one recorded effect beneath an outer journal lease. ReplayAction must only be called after its caller persisted an intent.
type StatusKind ¶
type StatusKind string
StatusKind is a redacted service state for CLI/JSON.
const ( StatusRunning StatusKind = "running" StatusStopped StatusKind = "stopped" StatusUnknown StatusKind = "unknown" StatusNotInstalled StatusKind = "not_installed" )
type SystemdAdapter ¶ added in v0.9.3
type SystemdAdapter struct {
// contains filtered or unexported fields
}
SystemdAdapter inspects and mutates the system mihari.service unit.
func NewSystemdAdapter ¶ added in v0.9.3
func NewSystemdAdapter(runner CommandRunner, hook ActionHook) *SystemdAdapter
NewSystemdAdapter constructs the production Linux definition adapter.
func NewSystemdAdapterWithConfig ¶ added in v0.9.3
func NewSystemdAdapterWithConfig(cfg SystemdConfig) *SystemdAdapter
NewSystemdAdapterWithConfig constructs an adapter from explicit OS boundaries.
func (*SystemdAdapter) DisableAutostartAndStop ¶ added in v0.9.3
func (a *SystemdAdapter) DisableAutostartAndStop(ctx context.Context) error
func (*SystemdAdapter) InspectDefinition ¶ added in v0.9.3
func (a *SystemdAdapter) InspectDefinition(ctx context.Context) (Definition, error)
func (*SystemdAdapter) ObserveAction ¶ added in v0.9.3
func (a *SystemdAdapter) ObserveAction(ctx context.Context, action DefinitionAction) (string, error)
func (*SystemdAdapter) Probe ¶ added in v0.9.3
func (a *SystemdAdapter) Probe(ctx context.Context) (Definition, error)
func (*SystemdAdapter) ReplayAction ¶ added in v0.9.3
func (a *SystemdAdapter) ReplayAction(ctx context.Context, action DefinitionAction) error
func (*SystemdAdapter) RestoreDefinition ¶ added in v0.9.3
func (a *SystemdAdapter) RestoreDefinition(ctx context.Context, def Definition) error
func (*SystemdAdapter) Start ¶ added in v0.9.3
func (a *SystemdAdapter) Start(ctx context.Context) error
func (*SystemdAdapter) WaitOwnedTreeExit ¶ added in v0.9.3
func (a *SystemdAdapter) WaitOwnedTreeExit(ctx context.Context) error
func (*SystemdAdapter) WriteDefinition ¶ added in v0.9.3
func (a *SystemdAdapter) WriteDefinition(ctx context.Context, def Definition) error
type SystemdConfig ¶ added in v0.9.3
type SystemdConfig struct {
Runner CommandRunner
Files DefinitionStore
Tree ProcessTree
Clock Clock
Hook ActionHook
Paths SystemdPaths
}
SystemdConfig injects the OS boundaries for an explicitly assembled adapter.
type SystemdPaths ¶ added in v0.9.3
type SystemdPaths struct {
Systemctl string
UnitDir string
UnitFile string
DropinDir string
WantsLink string
DevNull string
}
SystemdPaths is the absolute systemd layout used by the Linux adapter.
func DefaultSystemdPaths ¶ added in v0.9.3
func DefaultSystemdPaths() SystemdPaths
DefaultSystemdPaths returns the production /etc unit layout.