Documentation
¶
Overview ¶
Package daemon runs one user-session supervisor with an independently locked sync worker for each project volume.
LEGACY COMPATIBILITY SUNSET: 2026-12-15 (two months after 2026-10-15). This file migrates v0.17.x standalone per-volume daemons to the global supervisor. Do not extend its lifetime without an explicit migration decision. Removal checklist, in order:
- Remove the legacy `daemon run <folder>` CLI form and its validation call from Run; retain the argument-free global supervisor command.
- Remove reapLegacyDaemonIfNeeded calls from Start and worker discovery, and remove the reapAllLegacyDaemons call from supervisor startup.
- Replace Stop's unannounced-PID fallback with a fail-closed error; never signal a PID obtained only from daemon.pid.
- Delete this file and legacy_compat_test.go, remove TestHelperLegacyDaemon and TestStopRecoversLegacyDaemon, and remove the sunset override from docs.
- Run the daemon security, supervisor, CLI/desktop, and upgrade test suites.
Index ¶
- Constants
- func EnsureRunningAsync(volDir string, scanInterval, remoteInterval time.Duration)
- func EnsureRunningBestEffort(volDir string, scanInterval, remoteInterval time.Duration)
- func GlobalLockPath() (string, error)
- func GlobalLogPath() (string, error)
- func GlobalPidPath() (string, error)
- func GlobalRunning() (int, bool)
- func LockPath(volDir string) string
- func LogPath(volDir string) string
- func PidPath(volDir string) string
- func Run(folder string, scanInterval, remoteInterval time.Duration) error
- func Running(volDir string) (int, bool)
- func RunningCurrent(volDir string) (int, bool)
- func Start(folder, volDir string, scanInterval, remoteInterval time.Duration) (int, error)
- func Stop(volDir string) (bool, error)
- func ValidateLegacyRunFolder(folder string) error
- func WakeSupervisor() bool
Constants ¶
const LegacyCompatSunsetDate = "2026-12-15"
Variables ¶
This section is empty.
Functions ¶
func EnsureRunningAsync ¶ added in v0.18.0
EnsureRunningAsync starts the detached process before a short-lived hook exits, without waiting for the supervisor or volume worker to announce.
func EnsureRunningBestEffort ¶ added in v0.18.0
func GlobalLockPath ¶ added in v0.18.0
GlobalLockPath identifies the user-session supervisor's lifetime lock.
func GlobalLogPath ¶ added in v0.18.0
func GlobalPidPath ¶ added in v0.18.0
func GlobalRunning ¶ added in v0.18.0
func LockPath ¶ added in v0.13.0
LockPath is the file a live daemon holds an exclusive flock on for its whole lifetime. Liveness is the LOCK, not the pidfile: the kernel drops a flock when the holder dies — including at reboot, and including a crash — so a leftover daemon.pid can never be mistaken for a running daemon.
The pid alone cannot answer this. `kill(pid, 0)` only asks "does some process own this number", and daemon.pid outlives the process (it sits in ~/.bdrive, which survives reboots). Any same-user process that later recycles the pid used to read as a live daemon — which made `bdrive status` lie and, worse, made Start() a silent no-op, so the one documented recovery (`bdrive init`) left the folder unsynced.
func PidPath ¶
The volume store is keyed by the shared project volume, so exactly one daemon runs per volume and its pid/log live in the store dir.
func Running ¶
Running reports the daemon pid for a mount if one is alive. Aliveness is the flock on LockPath. The pid comes out of that same locked file — written by the holder itself (see announce) — and falls back to daemon.pid only for display: nothing binds THAT file's contents to the process holding the lock, and a daemon killed with -9 leaves it behind for the next process to inherit the number. Stop signals the announced pid only (see lockPid).
func RunningCurrent ¶ added in v0.18.0
RunningCurrent reports workers owned by the current-version global daemon. Resume must not mistake a standalone legacy daemon for a current supervisor.
func Start ¶
Start starts or wakes the global supervisor and waits for the requested worker. folder is retained for source compatibility; discovery uses the mount registry.
func Stop ¶
Stop terminates the daemon for a mount and waits for it to exit. Exit is observed by the lock being released, not by the pid disappearing: the pid could be recycled while we wait, and the lock cannot.
func ValidateLegacyRunFolder ¶ added in v0.18.0
ValidateLegacyRunFolder preserves the old command's project validation while the positional-folder spelling remains supported during migration.
func WakeSupervisor ¶ added in v0.18.0
func WakeSupervisor() bool
Types ¶
This section is empty.