daemon

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package daemon runs the watch loop as a background process and enforces a single running instance per machine. The lock is a real OS advisory file lock (flock on unix, LockFileEx on Windows) held for the process lifetime, so it is released automatically if the process dies and is immune to pid reuse. The file's contents are the holder's pid, kept only as metadata for stop/status.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRunning

func IsRunning(path string) bool

IsRunning reports whether an instance currently holds the lock. It probes by attempting to acquire: success (no one holds it) is released immediately. This is authoritative regardless of pid reuse, because it tests the live OS lock rather than trusting the recorded pid.

func Start

func Start(self string, watchArgs []string, p Paths) error

Start launches `self watchArgs...` as a detached background process whose output goes to the log file. The child acquires the lock itself; Start waits briefly to confirm an instance is holding it.

func Status

func Status(p Paths) (running bool, pid int)

Status reports whether the watch process is running and its pid.

func Stop

func Stop(p Paths) error

Stop terminates the running watch process. It verifies a live instance holds the lock before reading the pid and signalling, so it cannot kill an unrelated process that happens to reuse a stale pid. The terminated process releases its own lock on exit (or, on a hard Windows kill, leaves an unlocked file that the next start reclaims).

Types

type Lock

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

Lock is a held single-instance lock.

func Acquire

func Acquire(path string) (*Lock, error)

Acquire takes the lock, returning an error if another live instance holds it. The OS releases the lock automatically when this process exits, so there is no stale-lock reclaim logic and no TOCTOU window.

func (*Lock) Release

func (l *Lock) Release() error

Release drops the OS lock by closing the file handle. It deliberately does not remove the pidfile: unlinking after unlocking opens a window in which another process acquires the lock and we then delete the path out from under it, allowing two holders. A lingering unlocked pidfile is harmless because IsRunning probes the live lock, not the file's existence.

type Paths

type Paths struct {
	Pidfile string
	Logfile string
}

Paths locates the daemon's pidfile (also the lock) and its log file.

func DefaultPaths

func DefaultPaths() (Paths, error)

DefaultPaths returns the per-user daemon paths under the config directory.

Jump to

Keyboard shortcuts

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