Documentation
¶
Overview ¶
Package daemon implements background-process lifecycle for wick: Start/Stop/Restart/Status with a PID file. Targets headless environments where the system tray is not usable (Termux, SSH sessions, Linux servers).
The daemon re-execs the same binary with the existing `all` subcommand (server + worker in one process), detached from the caller's terminal so the parent shell can exit without killing it. Output goes to a log file alongside the PID file so users can tail it after start.
Index ¶
- Variables
- func InstallService(p Paths, appName string) error
- func Restart(p Paths, timeout time.Duration, args []string) (int, error)
- func Start(p Paths, args []string) (int, error)
- func Stop(p Paths, timeout time.Duration) error
- func TailLog(p Paths, n int64, w io.Writer) error
- func UninstallService(p Paths, appName string) error
- type Paths
- type ServiceState
- type Status
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyRunning = errors.New("daemon already running")
ErrAlreadyRunning signals Start was called while a live daemon was already recorded in the PID file.
var ErrNotInstalled = errors.New("service not installed")
ErrNotInstalled signals UninstallService was called when no service integration was found.
var ErrNotRunning = errors.New("daemon not running")
ErrNotRunning signals Stop was called with no live daemon recorded.
Functions ¶
func InstallService ¶
InstallService registers the binary to launch at user login / boot. Routing depends on the runtime environment:
GUI present (Win / Mac / desktop Linux) → forwards to the same internal/autostart entry the tray uses AND flips userconfig.AutoStartApp=true so the tray's `Auto-start app at login` checkbox stays in sync with what the CLI did. Headless (Termux, Linux server / RPi) → writes a daemon-style auto-start unit (systemd-user or Termux:Boot script) that runs `<exe> all` directly.
Re-running install over an existing install is safe — the GUI path rewrites the autostart entry, the headless path rewrites the unit.
func Restart ¶
Restart stops the running daemon (if any) then starts a fresh instance with the supplied argv tail.
func Start ¶
Start spawns the binary with the supplied subcommand detached from the caller's terminal, redirecting stdout+stderr to the daemon log file. Returns ErrAlreadyRunning if a live daemon is already recorded in the PID file.
args is the full argv tail passed to the spawned binary — callers choose between "all" (headless server + worker, default daemon mode) and "tray" (interactive tray icon on GUI hosts).
func Stop ¶
Stop sends SIGTERM (or the OS equivalent) to the running daemon and waits up to timeout for it to exit. Falls back to a force kill if the process is still alive at the deadline. ErrNotRunning is returned if no live daemon was recorded.
func TailLog ¶
TailLog copies the last n bytes of the daemon log to w. Convenience for `status` output. Returns nil if the log doesn't exist yet.
func UninstallService ¶
UninstallService removes whichever auto-start mechanism is in place. ErrNotInstalled is returned if nothing was registered. On the GUI path it also flips userconfig.AutoStartApp=false so the tray's checkbox follows the CLI.
Types ¶
type Paths ¶
type Paths struct {
Dir string // ~/.<appname>/
PIDFile string // run.pid
LogFile string // daemon.log
ExePath string // resolved path to the currently running binary
}
Paths bundles the per-app filesystem locations used by the daemon.
func ResolvePaths ¶
ResolvePaths returns the canonical daemon paths for an app. The directory is created if missing.
type ServiceState ¶
type ServiceState struct {
Installed bool // unit / script / login-item is registered with the OS
Active bool // best-effort runtime check; not always supported
Path string // canonical location of the registration
Backend string // "autostart-gui", "systemd-user", "termux-boot", "headless-unsupported"
Note string // free-form hint shown in `service status`
}
ServiceState describes whether per-OS auto-start integration is installed and (where the platform exposes it) whether the service is currently active.
func ServiceStatus ¶
func ServiceStatus(p Paths, appName string) (ServiceState, error)
ServiceStatus reports the registration state for whichever backend applies to the current host. On GUI hosts Installed/Active reflects the actual OS entry (what fires at login); a separate note flags when userconfig.AutoStartApp disagrees so the user can spot drift.