autostart

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package autostart registers beardrive to start syncing again when the user logs in, so a reboot doesn't silently stop sync.

The daemon is a detached child process (see internal/daemon): a reboot kills it and nothing brought it back — every project stayed unsynced until someone ran `bdrive init` in that folder again. Agent hooks still synced per turn, which is exactly what made the gap easy to miss: the folder looked fine while an agent was working in it and went stale the moment one wasn't.

The unit registered here is ONE per machine, not one per project. It runs `bdrive resume`, which walks the mount registry and starts a daemon for every enrolled, unpaused mount — so mounts added or removed later need no change to the registration, and `bdrive stop` keeps meaning "stay stopped".

Platform support: macOS (launchd user agent), Linux (systemd user unit), and Windows (a per-user Run entry). Anything else gets the stub, which returns ErrUnsupported — callers already treat that as "nothing to do".

No implementation shells out to a service manager (`launchctl`, `systemctl`, `schtasks`). Writing the registration IS the registration: launchd reads ~/Library/LaunchAgents at login, systemd reads the enable symlink in default.target.wants, Explorer reads HKCU\...\Run at logon. All of them matter only at the NEXT login — the caller has just started the daemon for this session — and shelling out would let a test or a packaging script register something real as a side effect, or fail on a machine with no session bus at all (ssh, container, CI).

Index

Constants

View Source
const Unit = "beardrive.service"

Unit is the systemd user unit's name, and the file it lives in.

Variables

View Source
var ErrUnsupported = errors.New("autostart is not supported on this platform yet")

ErrUnsupported is returned by Install/Uninstall on platforms that have no implementation yet. Callers treat it as "nothing to do", never as failure: autostart is a convenience, and a hard error would break `bdrive init` on a platform that syncs perfectly well without it.

Functions

func Installed

func Installed() bool

Installed reports whether the unit is both present and enabled — a unit file with no wants symlink never starts, so it does not count.

func Path

func Path() (string, error)

Path is the unit file this package owns.

Types

type Result

type Result struct {
	Path    string // the file written (or that would be)
	Changed bool   // false when it was already correct
}

Result reports what Install did, mirroring agenthooks.Result so callers can print the two the same way.

func Install

func Install() (Result, error)

Install writes the unit and enables it by linking it into default.target.wants. Both steps are needed: systemd ignores a unit file that nothing wants.

func Uninstall

func Uninstall() (Result, error)

Uninstall removes the enable symlink and the unit. Missing is success.

systemd keeps its loaded copy until `daemon-reload` or the next login, but the daemons already running are untouched either way, and nothing will start at the next login — which is what "uninstalled" has to mean here.

Jump to

Keyboard shortcuts

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