service

package
v0.9.2-dev.1 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: GPL-3.0 Imports: 9 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 and controls Mihari as a native OS service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 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 Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager is the production entry for service control.

func New

func New(opts Options) *Manager

New returns a Manager with defaults.

func (*Manager) Install

func (m *Manager) Install() error

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

func (m *Manager) Reinstall() error

Reinstall stops the service, removes registration, copies this binary into the install directory, re-registers ImagePath, and starts the service.

func (*Manager) Restart

func (m *Manager) Restart() error

Restart restarts the service.

func (*Manager) Run

func (m *Manager) Run() error

Run executes under the service manager (or foreground when interactive).

func (*Manager) Start

func (m *Manager) Start() error

Start 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) Stop

func (m *Manager) Stop() error

Stop stops the service.

func (*Manager) Uninstall

func (m *Manager) Uninstall() error

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

func (m *Manager) UpdateInstalledBinary() (bool, error)

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 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 RunFunc

type RunFunc func(ctx context.Context) error

RunFunc is the daemon body; it blocks until ctx is cancelled.

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"
)

Jump to

Keyboard shortcuts

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