runlock

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package runlock is the single-instance lock of a machine's runtime: an exclusive flock on a guard file in the data folder, held for as long as the process lives, so the kernel drops it when the process dies however it dies. Beside it lies the file naming the holder and its port: it is what a newcomer's refusal quotes, and what a runtime older than the guard is recognised by (that one is asked on its port's health route, as it asked itself).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	File string
	// App is the name a runtime's health route answers with ("app").
	App string
	// Health asks a port's health route for its app name; nil asks http://127.0.0.1:<port>/api/health.
	Health func(port int) (string, bool)
	Now    func() time.Time
}

Config says where the lock is and how a holder is recognised.

type HeldError

type HeldError struct{ PID, Port int }

HeldError: a live runtime holds the lock. PID and Port are zero when the holder has not named itself yet.

func (*HeldError) Error

func (e *HeldError) Error() string

type Lock

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

Lock is a lock this process holds.

func Acquire

func Acquire(cfg Config, port int) (*Lock, error)

Acquire takes the lock for this process on port. While another process holds the guard it is a *HeldError, whether or not that process answers on its port. With the guard taken, the holder file is only a leftover: of a process that is gone, or of a runtime older than the guard, which is a *HeldError while it answers on its port.

func (*Lock) Release

func (l *Lock) Release()

Release removes the holder file while it is still this process's, then lets the guard go.

Jump to

Keyboard shortcuts

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