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 ¶
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 ¶
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 Stop ¶
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 ¶
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 ¶
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.