Documentation
¶
Overview ¶
Package lockfile is a remote-host mutex implemented on top of SFTP.
SFTP doesn't expose POSIX flock, so we use SFTP's open-with-CREATE-and-EXCL to atomically materialize a small JSON file. The file's mtime gates TTL staleness — if a previous deploy crashed and left the lock orphaned past the configured TTL, we steal it (logging loudly).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrAlreadyHeld = errors.New("lock is already held by another deploy")
)
Errors returned by Acquire.
Functions ¶
func Acquire ¶
func Acquire(ctx context.Context, sc *sftp.Client, path string, ttl time.Duration, force bool) (*Handle, *Lock, bool, error)
Acquire creates the lock file atomically. If the file already exists and its mtime is within ttl, returns ErrAlreadyHeld. If older than ttl, the caller is given the chance to steal via force.
On steal, the existing lock content is returned so the caller can log who originally held it.
Types ¶
type Handle ¶
type Handle struct {
// contains filtered or unexported fields
}
Handle is what Acquire returns. Call Release when done — the deferred Release in a deploy is critical.
type Lock ¶
type Lock struct {
HeldBy string `json:"held_by"`
Hostname string `json:"hostname"`
PID int `json:"pid"`
AcquiredAt time.Time `json:"acquired_at"`
}
Lock describes the file written to the remote lock path. It's not security state — it's diagnostic so a human can tell who else is in the middle of deploying.