Documentation
¶
Index ¶
- type FileLock
- func (fl *FileLock) GetLockFilePath() string
- func (fl *FileLock) GetPID() (int, error)
- func (fl *FileLock) IsLocked() bool
- func (fl *FileLock) ReadPort() (int, error)
- func (fl *FileLock) ReadVersion() (string, error)
- func (fl *FileLock) RemoveRuntimeFiles() error
- func (fl *FileLock) TryLock() error
- func (fl *FileLock) Unlock() error
- func (fl *FileLock) WritePort(port int) error
- func (fl *FileLock) WriteVersion(version string) error
- type PortFile
- type VersionFile
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileLock ¶
type FileLock struct {
// contains filtered or unexported fields
}
FileLock manages exclusive file locking for single-instance enforcement. The lock is automatically released when the process dies, even if it crashes. It also stores the current process PID for signal-based shutdown.
func NewFileLock ¶
NewFileLock creates a new file lock instance. The lock file will be created in the specified config directory.
func (*FileLock) GetLockFilePath ¶
GetLockFilePath returns the lock file path for debugging purposes.
func (*FileLock) GetPID ¶
GetPID returns the PID stored in the lock file. Returns error if the lock file doesn't exist or contains invalid data.
func (*FileLock) IsLocked ¶
IsLocked checks if the lock is currently held by another process. Returns false if the lock is available or if this process holds it.
func (*FileLock) ReadPort ¶
ReadPort returns the port recorded by the running server. Callers must gate on IsLocked() and treat any error as "port unknown" (fall back to config).
func (*FileLock) ReadVersion ¶
ReadVersion returns the version recorded by the running server. Callers must gate on IsLocked() and treat any error as "version unknown" — servers started by builds predating version recording never wrote one.
func (*FileLock) RemoveRuntimeFiles ¶
RemoveRuntimeFiles deletes every runtime artifact tied to this lock (port and version files). Unlock already does this for the lock holder; the stop command uses it to clean up after a server that was killed without releasing the lock itself. Adding a new runtime artifact means adding it here (and to the per-platform constructors) so no removal site is missed.
func (*FileLock) TryLock ¶
TryLock attempts to acquire the file lock. Returns an error if the lock is already held by another process. The lock file remains on disk but is unlocked when this process dies. On success, stores the current process PID in the lock file for shutdown signals.
func (*FileLock) Unlock ¶
Unlock releases the file lock. Safe to call multiple times; subsequent calls are no-ops.
func (*FileLock) WritePort ¶
WritePort records the port the running server is listening on. It is a runtime artifact tied to this lock's lifetime: written after TryLock and removed by Unlock (or RemoveRuntimeFiles on the stopping side).
func (*FileLock) WriteVersion ¶
WriteVersion records the running server's build version. Same lifetime rules as WritePort.
type PortFile ¶
type PortFile struct {
// contains filtered or unexported fields
}
PortFile records the port the running server is actually listening on. Other CLI processes (cc/profile/log/status/open) read it to discover the live port, since the server port is intentionally not persisted in the config file. See .design/runtime-port-file.md.
func NewPortFile ¶
NewPortFile creates a port file handle for the given config directory.
func (*PortFile) Read ¶
Read returns the recorded port. Callers should treat any error as "port unknown" and fall back to the configured port.
type VersionFile ¶
type VersionFile struct {
// contains filtered or unexported fields
}
VersionFile records the build version of the running server. Launchers read it to tell whether the running server matches their own version — a missing or unreadable file means "version unknown" (e.g. a server started by a build predating version recording). Same lifecycle and reader rules as PortFile.
func NewVersionFile ¶
func NewVersionFile(configDir string) *VersionFile
NewVersionFile creates a version file handle for the given config directory.
func (*VersionFile) Read ¶
func (vf *VersionFile) Read() (string, error)
Read returns the recorded version. Callers should treat any error as "version unknown".
func (*VersionFile) Remove ¶
func (vf *VersionFile) Remove() error
Remove deletes the version file. A missing file is not an error.
func (*VersionFile) Write ¶
func (vf *VersionFile) Write(version string) error
Write records the running server's version.