Help us shape the future of Go! Take the 2026 Go Developer Survey

daemon

package
v0.18.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: AGPL-3.0 Imports: 22 Imported by: 0

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:

  1. Remove the legacy `daemon run <folder>` CLI form and its validation call from Run; retain the argument-free global supervisor command.
  2. Remove reapLegacyDaemonIfNeeded calls from Start and worker discovery, and remove the reapAllLegacyDaemons call from supervisor startup.
  3. Replace Stop's unannounced-PID fallback with a fail-closed error; never signal a PID obtained only from daemon.pid.
  4. Delete this file and legacy_compat_test.go, remove TestHelperLegacyDaemon and TestStopRecoversLegacyDaemon, and remove the sunset override from docs.
  5. Run the daemon security, supervisor, CLI/desktop, and upgrade test suites.

Index

Constants

View Source
const LegacyCompatSunsetDate = "2026-12-15"

Variables

This section is empty.

Functions

func EnsureRunningAsync added in v0.18.0

func EnsureRunningAsync(volDir string, scanInterval, remoteInterval time.Duration)

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 EnsureRunningBestEffort(volDir string, scanInterval, remoteInterval time.Duration)

func GlobalLockPath added in v0.18.0

func GlobalLockPath() (string, error)

GlobalLockPath identifies the user-session supervisor's lifetime lock.

func GlobalLogPath added in v0.18.0

func GlobalLogPath() (string, error)

func GlobalPidPath added in v0.18.0

func GlobalPidPath() (string, error)

func GlobalRunning added in v0.18.0

func GlobalRunning() (int, bool)

func LockPath added in v0.13.0

func LockPath(volDir string) string

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 LogPath

func LogPath(volDir string) string

func PidPath

func PidPath(volDir string) string

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 Run

func Run(folder string, scanInterval, remoteInterval time.Duration) error

Run owns the user-session lock and reconciles independently locked workers.

func Running

func Running(volDir string) (int, bool)

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

func RunningCurrent(volDir string) (int, bool)

RunningCurrent reports workers owned by the current-version global daemon. Resume must not mistake a standalone legacy daemon for a current supervisor.

func Start

func Start(folder, volDir string, scanInterval, remoteInterval time.Duration) (int, error)

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

func Stop(volDir string) (bool, error)

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

func ValidateLegacyRunFolder(folder string) error

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.

Jump to

Keyboard shortcuts

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