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) RemovePort() error
- func (fl *FileLock) TryLock() error
- func (fl *FileLock) Unlock() error
- func (fl *FileLock) WritePort(port int) error
- type PortFile
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 ¶ added in v0.260716.1
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) RemovePort ¶ added in v0.260716.1
RemovePort deletes the runtime port file. 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.
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.
type PortFile ¶ added in v0.260716.1
type PortFile struct {
// contains filtered or unexported fields
}
PortFile records the port the running server is actually listening on. Like the PID lock file, it is a runtime artifact in the config directory, not configuration: the server writes it right after acquiring the file lock and removes it on shutdown. 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.
Readers must gate on FileLock.IsLocked(): a stale port file can survive a crashed server, but the flock is always released by the OS.
func NewPortFile ¶ added in v0.260716.1
NewPortFile creates a port file handle for the given config directory.
func (*PortFile) Read ¶ added in v0.260716.1
Read returns the recorded port. Callers should treat any error as "port unknown" and fall back to the configured port.