Documentation
¶
Index ¶
Constants ¶
const DefaultLockFile = "installer.lock"
DefaultLockFile is the recommended path for the installer lock file. Callers may override (e.g., tests use t.TempDir() + this filename).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
Lock represents an acquired installer lock. Callers MUST call Release() when done; the recommended pattern is `defer lk.Release()` immediately after a successful Acquire.
func Acquire ¶
Acquire takes an exclusive non-blocking flock on path. Returns a *Lock on success or an error describing why acquisition failed.
If another process holds the lock AND the recorded PID corresponds to a live nftban-installer process, the returned error message includes that PID for operator diagnosis ("another installer is running (pid N)").
The lock file's parent directory is created (mkdir -p) if missing — on fresh installs the state-dir may not exist yet because FHS bootstrap happens in phasePrepare downstream.
Stale-PID safety: the recorded PID in the lock file is informational only. The authoritative lock source is the kernel's flock state. If the previous holder exited (cleanly or via crash/kill), the kernel releases the flock automatically and the next Acquire succeeds — the stale PID is overwritten with the new holder's PID.
func (*Lock) Release ¶
Release releases the flock and closes the file descriptor. Idempotent and safe to call on a nil *Lock. The lock file itself is intentionally NOT deleted — leaving it preserves the recorded PID for post-mortem inspection and avoids a delete-race window.
Note: on os.Exit() Go skips deferred calls, so callers that use os.Exit (e.g., cmd/nftban-installer/main.go does this with the computed exit code) MUST call Release() explicitly before os.Exit.