Skip to content

Run the daemon on Linux - #160

Draft
Kryolisc wants to merge 7 commits into
danielmaier42:mainfrom
Kryolisc:feature/linux-services
Draft

Kryolisc wants to merge 7 commits into
danielmaier42:mainfrom
Kryolisc:feature/linux-services

Conversation

@Kryolisc

@Kryolisc Kryolisc commented Nov 6, 2026

Copy link
Copy Markdown

The second of the Linux PRs. It builds on #159: the first commit here is #159, so please review that one first. After #159 is merged, this PR shows only its own three commits. The plan and the state of the port are in docs/linux/PLAN.md. On macOS nothing changes, apart from one sentence in the run system prompt (see below).

What changes

On Linux the daemon, the CLI and the dashboard now work as a real installation. There is no window yet (PR 3) and no package yet (PR 4).

Feature On Linux
Autostart dispatchqd install writes a systemd user service. It starts at login and restarts a daemon that exits. On stop, systemd signals only the daemon, which winds down its runs within its 30 s grace, as under launchd.
Sleep during a run Held off with a logind lock (systemd-inhibit), the counterpart of caffeinate.
Wake from sleep Not offered. Linux needs root to set a wake alarm. The log says so at startup.
Desktop notifications notify-send. Pushover, ntfy and webhooks work as before.
Folder and save dialogs kdialog on KDE Plasma, zenity elsewhere.
Continue in a terminal The user's default terminal (xdg-terminal-exec), else Konsole, GNOME Terminal or x-terminal-emulator.
Data ~/.local/share/dispatchq (XDG). DISPATCHQ_HOME still overrides it.
Updates and uninstall Not from the app until packages exist. The dashboard says so and links to the releases.

The dashboard asks the daemon for its platform. On macOS every text stays as it is. On Linux it says "this computer", shows Ctrl+ shortcuts, and leaves out macOS-only rows.

Notifications About
Notifications settings on Linux About on Linux
System Appearance
System settings on Linux Appearance on Linux

Changes that also reach macOS

  • Run system prompt: it no longer names ~/Library/Application Support/dispatchq as the fallback data directory. It now says that DISPATCHQ_HOME is always set for a run, which the daemon guarantees.
  • Continue in Terminal: the temporary file with a provider's secret variables is now also removed after two minutes, in case the terminal's shell never ran.
  • CI: a new build-test-linux job. scripts/pkgtest (the macOS installer script test) now builds on macOS only.

Verified on a real system

Ubuntu, KDE Plasma (Wayland), systemd 259:

  • dispatchqd install → the service is enabled and active. systemd-analyze verify accepts the unit. The running daemon has DISPATCHQ_HOME from the unit.
  • A script task with --notify ran for 8 s. During the run logind listed DispatchQ sleep:idle Running a queued task block, and after the run the lock was gone. The failure notification went out on the session bus as Notify("DispatchQ", …, "DispatchQ ✗ Linux e2e failed", …).
  • kill -9 of the daemon → systemd started a new one about 5 s later (NRestarts=1).
  • A kdialog started through the same systemd-run --user --wait --pipe path opened on the desktop, and its exit status came back.
  • dispatchqd uninstall → the unit file is gone, the service is not found, the port is free, and the daemon logged a clean stop. The error log stayed empty for the whole test.

Checks

Check Result
Linux: go vet, go test ./... -race, golangci-lint v2.12.2 pass, 0 findings (the old main_other.go finding is fixed)
macOS darwin/arm64: build, vet, test compile, golangci-lint v2.12.2 pass, 0 findings. Cross-checked from Linux with a cgo stub overlay. The macOS tests need this PR's CI run.
Web: typecheck, lint, 223 tests pass
Self-review (/code-review) 10 findings: 9 fixed, 1 recorded as untested (GNOME, below)

Open, for discussion

  • GNOME is untested. Its power daemon may suspend an idle machine although dispatchq holds the logind lock. KDE Plasma was tested. It is recorded in docs/linux/PLAN.md and gets tested before a release.
  • The service runs only while the user is logged in. Running after logout would need lingering and has the same credential questions as the Windows plan names.
  • Notification clicks do nothing yet. They need the window (PR 3).

🤖 Generated with Claude Code

Lukas Wolfrum and others added 7 commits November 6, 2026 12:11
The daemon called launchctl, pmset, caffeinate, osascript, sw_vers and the
macOS Installer directly. On any other system those calls failed at run time:
`dispatchqd install` stopped the running daemon and then failed at launchctl,
and every notification and wake attempt logged an error.

newPlatform now supplies these services, with one file per system.
platform_darwin.go wires the existing macOS implementations without change.
platform_other.go wires none. The daemon skips a missing service, and the
dashboard endpoints for a missing dialog, terminal, uninstaller or update
service answer "not available". `dispatchqd install` and `uninstall` refuse
before they stop anything.

The engine keeps its reference-counted sleep guard and gets the inhibitor
injected. system.Hold holds `caffeinate -i` on macOS, and a later Linux
platform can use it for systemd-inhibit. A hold that fails is now retried
by the next run that starts, not only after all runs end.

POST /api/update/relaunch now answers 503 without an update service, the
same as the other update endpoints.

This prepares Linux support and follows the "small interfaces around
operating-system operations" direction of docs/windows/PLAN.md (danielmaier42#151).
macOS behavior does not change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Linux gets its own platform wiring (platform_linux.go):

- `dispatchqd install` writes a systemd user service with Restart=always,
  KillMode=mixed and TimeoutStopSec=60. On stop, systemd signals only the
  daemon, which winds down its runs within its 30-second grace, as under
  launchd. The unit pins DISPATCHQ_HOME, because the user manager does not
  read the shell profile. The unit folder comes from the manager's own
  environment.
- Runs hold a logind sleep lock through systemd-inhibit (system.Hold).
- Desktop notifications go through notify-send (notify.FreeDesktop).
- Folder and save dialogs use kdialog on KDE Plasma and zenity elsewhere.
  They start through `systemd-run --user --wait --pipe`, so they get the
  session's current display even when the daemon started first at login.
- "Continue in terminal" starts xdg-terminal-exec, Konsole, GNOME Terminal
  or x-terminal-emulator as a transient user unit, so a service restart
  does not close it. An unread secret environment file is now removed
  after two minutes on every system.
- The data directory is $XDG_DATA_HOME/dispatchq (~/.local/share/dispatchq).
- Wake from sleep, self-update and the uninstaller are not offered: they
  need root or a package that does not exist yet.

The API reports the platform in /api/health and names the system in the
feedback footer. Without an update service, /api/update says
"unavailable". `dispatchq uninstall` explains the manual steps off macOS.
The run system prompt no longer names a macOS fallback path, because
DISPATCHQ_HOME is always set for a run.

scripts/pkgtest tests the macOS installer script and now builds on macOS
only. cmd/dispatchqapp/main_other.go gets its missing package comment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The dashboard reads the daemon's platform from /api/health. On macOS every
text stays as it was. Elsewhere it says "this computer" instead of "this Mac",
shows "Ctrl+" instead of "⌘", names the file manager and a terminal instead
of Finder and Terminal, and leaves out macOS-only rows: System Settings for
notifications, and the uninstaller. The New task and Refresh shortcuts are
only shown where a native menu handles them.

Settings → About shows a link to the releases when the system cannot install
updates. The sidebar search label is cut, not wrapped, when "Ctrl+K" makes
it longer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The new build-test-linux job runs vet, build, race tests and golangci-lint
on ubuntu-latest, so Linux-only files are checked too. The macOS job only
compiles darwin files.

README gets a "Linux (preview)" section and the Linux paths. The plan and
the state of the port live in docs/linux/PLAN.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of danielmaier42#159: `dispatchq run-now` builds its own engine and never got a
sleep inhibitor. Before the platform layer, the engine started `caffeinate`
itself, so a manual run on macOS lost its sleep protection.

system.DefaultSleepInhibitor now supplies the platform's sleep hold to both
the daemon and the CLI's run-now engine. The code is the same as in danielmaier42#151, so
the Windows branch merges onto it without conflicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The review of danielmaier42#159 found that the CLI's run-now engine got no sleep hold.
danielmaier42#159 now takes it from system.DefaultSleepInhibitor. On Linux that hold was
still set only in the daemon's platform wiring, so a manual run could be
suspended. sleep_linux.go now returns the systemd-inhibit hold, and both the
daemon and run-now use it. The run-now regression test now also fails on
Linux without the fix.

The fallback platform's build tag also excludes Windows, as in danielmaier42#151.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@danielmaier42

Copy link
Copy Markdown
Owner

The shared platform layer and Windows implementation have now landed on main through #151. That includes the complete foundation from #159, its run-now sleep-protection fix, and the subsequent platform, process-lifecycle and update abstractions.

Could you please rebase this PR onto the latest main and adapt the Linux services to the current abstractions? That will let me review the Linux-specific changes against the foundation now in use. There is no need to carry or merge #159 separately anymore. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants