daemon

package
v1.0.0-beta.37 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: AGPL-3.0 Imports: 50 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 daemon is `moin daemon`: the process on a server that dials out to the hub and holds one WebSocket session to it.

Index

Constants

View Source
const DefaultRulesFile = "/etc/" + build.Name + "/rules"

DefaultRulesFile is where the owner of a server writes what the daemon may do there. MOIN_RULES overrides it. The daemon never writes this file.

View Source
const DefaultStateDir = "/var/lib/" + build.Name

DefaultStateDir is where a root daemon keeps its state. MOIN_STATE_DIR overrides it, for example when a daemon runs without root in development.

Variables

View Source
var ErrNotRegistered = errors.New("daemon is not registered: run `" + build.Name + " daemon register --url <hub> --token <install token>`")

ErrNotRegistered means the daemon has no state yet and needs `moin daemon register`.

Functions

func FromAgent

func FromAgent(ctx context.Context, dir string) error

FromAgent is `moin agent`, which only the old unit runs. It moves the server to the daemon and waits for systemd to stop it. When the move fails, it runs the daemon under the old unit, so the server stays online, and the next start tries again.

func Hello

func Hello(dir string) protocol.Hello

Hello describes this daemon and server, with its rules, the names of the secrets it keeps in dir and the env keys of its apps: never a value.

func LoadRules

func LoadRules(file string) (*protocol.Rules, error)

LoadRules reads the rules file. Without one, moin may do everything. A file with a mistake is an error, so a typo never allows what it meant to stop.

func RulesFile

func RulesFile() string

RulesFile returns MOIN_RULES, else DefaultRulesFile.

func Run

func Run(ctx context.Context, dir string, state State) error

Run holds the session until ctx ends and reconnects when it drops. A rejected daemon token ends Run, because retrying cannot fix it. Deploys keep running across reconnects.

func StateDir

func StateDir() string

StateDir returns MOIN_STATE_DIR or DefaultStateDir.

func Uninstall

func Uninstall(ctx context.Context, dir string, withApps bool, logf func(string, ...any)) ([]string, error)

Uninstall removes the daemon from this server: its systemd service, its binary and its state in dir. The apps keep running with their data, the proxy, the tunnel and the firewall, unless withApps: then it takes all of them down too, data included. It returns what stays on the server.

Types

type State

type State struct {
	URL         string `json:"url"`
	ServerID    string `json:"server_id"`
	DaemonToken string `json:"daemon_token"`
}

State is what the daemon keeps between restarts.

func LoadState

func LoadState(dir string) (State, error)

LoadState reads the state from dir.

func Register

func Register(ctx context.Context, dir, baseURL, installToken string) (State, error)

Register trades a one-time install token for a daemon token and saves it in dir. Running it again with a new install token moves the daemon to that server.

Jump to

Keyboard shortcuts

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