Documentation
¶
Index ¶
- Constants
- Variables
- func DetectSystemdService(cgroup []byte, service string) (managed, matches bool)
- func RefreshBusy(ctx context.Context) error
- func RemoveRefreshOutcome(path string) error
- func RestorePreviousUnit(path string) error
- func SystemdRun(exe, stateDir string, fromGen int, validate func(context.Context) error) func(context.Context, func()) error
- func WaitRefreshAck(ctx context.Context, path, token string) error
- func WriteRefreshAck(path, token string) error
- func WriteRefreshOutcome(path string, outcome RefreshOutcome) error
- func WriteUnitWithPrevious(path string, contents []byte) (bool, error)
- type CommandRunner
- type RefreshConfig
- type RefreshOutcome
- type UnitRenderer
Constants ¶
const ( RefreshOK = "ok" RefreshRolledBack = "rolled_back" RefreshFailed = "failed" )
const ( ServiceName = "mistgate-node.service" RefreshUnitName = "mistgate-unit-refresh" RefreshAckFile = "unit-refresh.ack" )
const Generation = 3
Generation is written into the hardened mistgate-node.service unit as MISTGATE_UNIT_GEN.
const RefreshOutcomeFile = "unit-refresh.outcome"
Variables ¶
var ErrBusy = errors.New("busy")
var ErrLaunch = errors.New("unit refresh launch failed")
var ErrPreflight = errors.New("unit refresh preflight failed")
Functions ¶
func DetectSystemdService ¶
DetectSystemdService reports whether the process belongs to a systemd cgroup and whether it belongs to the exact requested service. Cgroup path components are compared as complete names so similarly named units do not match.
func RefreshBusy ¶
RefreshBusy reports whether the fixed transient refresh unit is already loaded. A current-generation agent uses it before returning a no-op so a second apply during the installer restart window still reports busy.
func RemoveRefreshOutcome ¶
func RestorePreviousUnit ¶
func SystemdRun ¶
func SystemdRun(exe, stateDir string, fromGen int, validate func(context.Context) error) func(context.Context, func()) error
SystemdRun starts the installed binary in a transient root unit so it can rewrite its own systemd unit outside its service sandbox. The fixed unit name makes concurrent refresh attempts fail closed. The helper waits for an ack file so the panel's CommandResult is sent before it can restart this service.
func WriteRefreshAck ¶
func WriteRefreshOutcome ¶
func WriteRefreshOutcome(path string, outcome RefreshOutcome) error
Types ¶
type RefreshConfig ¶
type RefreshConfig struct {
UnitPath string
Binary string
StateDir string
FromGen int
ToGen int
RAMBytes uint64
Render UnitRenderer
Run CommandRunner
Now func() time.Time
Sleep func(context.Context, time.Duration)
WaitTimeout time.Duration
CommandTimeout time.Duration
StableFor time.Duration
PollInterval time.Duration
}
type RefreshOutcome ¶
type RefreshOutcome struct {
At time.Time `json:"at"`
FromGen int `json:"from_gen"`
ToGen int `json:"to_gen"`
Result string `json:"result"`
Reason string `json:"reason,omitempty"`
}
func ReadRefreshOutcome ¶
func ReadRefreshOutcome(path string) (RefreshOutcome, error)
func RefreshInstall ¶
func RefreshInstall(ctx context.Context, c RefreshConfig) (RefreshOutcome, error)
RefreshInstall replaces the unit atomically, then reloads and restarts the service. A service that does not remain active for the stability window is rolled back to the saved unit and restarted again.