Repository navigation
Conversation
flock stop shuts the daemon down and every service it runs, and flock start starts it again. Neither changes the service, so the daemon still starts at the next login (on Linux, with the computer). On Windows the daemon has no signals, so it gets a new POST /v1/stop API call that ends Run as SIGTERM does: services shut down cleanly and the daemon exits with code 0, which the watchdog doesn't restart, so the scheduled task ends too. A daemon that doesn't stop within a minute, or one without the call, is ended like flock restart does. On macOS the LaunchAgent is booted out and bootstrapped again, on Linux the unit is stopped and started. Refs flock-php#92
The tray menu shows Stop Flock under Restart Flock while the daemon runs, and the panel has a Stop link next to Restart. Both run flock stop; afterwards the existing Start Flock item and button appear. Refs flock-php#92
Quitting the tray app leaves the daemon and the sites running, which "Quit Flock" didn't make clear. The macOS app says "Quit Flock Bar" for the same reason. Linux keeps "Quit Flock": its app can also be a window without a tray icon. Refs flock-php#92
|
@N7z Could you add start/stop controls to this line in each app? When stopped, only start should appear. When started, both stop and restart appear.
|
|
Also, please contribute the Mac and Linux UIs as well. We'd like to avoid having the platforms drift apart as much as possible |
flock stop unloads the LaunchAgent, and flock restart then said the daemon wasn't installed, so the apps' Start Flock (which runs flock restart) failed after a stop. It now loads the agent again when it isn't loaded. Refs flock-php#92
The Daemon row in Settings > General has Stop Daemon next to Restart Daemon on Windows, macOS and Linux. While the daemon is stopped, Settings already shows only Start Flock instead of the panes. After a successful stop the Windows and Linux apps show the daemon as stopped at once, instead of the stale status until the next poll: on Windows, reading the status of a daemon that just stopped takes seconds to fail. Refs flock-php#92
The macOS panel's footer has Stop next to Restart, and the Linux tray menu has Stop Flock under Restart Flock while the daemon runs, as the Windows tray has. Both run flock stop; afterwards Start Flock shows instead. Refs flock-php#92
|
Thanks for review ! , I added Stop to Settings > General in all three apps, and to the macOS panel and the Linux tray menu. I tested it on Windows. I can’t build the macOS and Linux apps, so I’m relying on CI for those. |
There was a problem hiding this comment.
🟡 Changes recommended
Stop handling can falsely report success while services remain running or the Windows daemon restarts, while status timeouts and Linux service signaling can prevent reliable, graceful shutdown.
5 open issues
What changed in this PR
Adds temporary daemon stop/start controls to free resources without disabling automatic startup, addressing the core request in #92.
Changes:
- Adds
flock stopandflock start, with platform-specific lifecycle handling and a daemon stop API. - Adds Stop controls and busy-state handling across the desktop apps, plus clearer Windows tray quit labels.
- Adds shutdown tests and documents stopping and starting Flock.
| File | Description |
|---|---|
| windows/README.md | Adds manual stop/start checks. |
| windows/Flock.Tray/ViewModels/PanelViewModel.cs | Adds Stop command and lifecycle guards. |
| windows/Flock.Tray/ViewModels/GeneralViewModel.cs | Exposes Stop and stopping state. |
| windows/Flock.Tray/Settings/GeneralPane.xaml | Adds Stop Daemon button. |
| windows/Flock.Tray/PanelWindow.xaml | Adds Stop link and clarifies Quit label. |
| windows/Flock.Tray/Infrastructure/RuntimeService.cs | Shares stop/restart execution and updates status. |
| windows/Flock.Tray/App.xaml.cs | Adds Stop Flock menu action. |
| windows/Flock.Tray.Tests/GeneralViewModelTests.cs | Tests Stop availability and restart blocking. |
| macos/Sources/FlockUI/Settings/SettingsWindow.swift | Disables Start while stopping. |
| macos/Sources/FlockUI/Settings/GeneralPane.swift | Adds Stop Daemon control. |
| macos/Sources/FlockUI/PanelView.swift | Adds Stop and stopping-state feedback. |
| macos/Sources/FlockUI/AppModel.swift | Runs the stop command. |
| linux/src/window.rs | Disables Start while stopping. |
| linux/src/tray.rs | Adds Stop Flock menu item. |
| linux/src/panes/general.rs | Adds Stop Daemon and lifecycle guards. |
| linux/src/model.rs | Tracks stopping and clears stopped status. |
| linux/src/main.rs | Routes tray Stop action. |
| internal/daemon/daemon.go | Adds API-triggered lifecycle cancellation. |
| internal/daemon/daemon_test.go | Tests that Stop ends daemon execution. |
| internal/cli/stop.go | Implements stop/start commands. |
| internal/cli/root.go | Registers stop/start commands. |
| internal/cli/install_windows.go | Adds graceful stop, fallback, and startup handling. |
| internal/cli/install_linux.go | Adds systemd stop/start operations. |
| internal/cli/install_darwin.go | Adds LaunchAgent stop/start and shared bootstrap logic. |
| internal/api/api.go | Adds stop endpoint and client method. |
| internal/api/api_test.go | Tests stop dispatch, authentication, and HTTP method. |
| docs/installation.md | Explains stopping and automatic startup behavior. |
| docs/cli.md | Lists stop/start commands. |
Review effort: Balanced
- A daemon stopped while an API request still runs (an install) cuts it off and exits with code 0, instead of returning the shutdown timeout as an error, which made the Windows watchdog start it again. - On Windows, flock stop fails when the fallback could not end the daemon, instead of reporting it stopped. - On macOS, flock stop fails when launchd still has the agent loaded. - flock stop no longer gives up when the status read fails for another reason than the daemon not running: like flock restart, it only uses it for the pid. Refs flock-php#92
# Conflicts: # internal/cli/root.go



Fixes #92
Adds a way to stop the Flock daemon and every service it runs, and to start it again, from the CLI and the Windows tray. Stopping only lasts until the next start: the scheduled task (LaunchAgent, systemd unit) isn't changed, so the daemon still starts at the next login.
CLI
flock stopstops the daemon and all services.flock startstarts them again and waits until the daemon answers.How stopping works
Windows. The daemon gets no signals, so there's a new
POST /v1/stopAPI call. It endsdaemon.Runthe way SIGTERM does on the other platforms: every service shuts down cleanly (mysqladmin shutdown,pg_ctl stop -m fast, Valkey'sSHUTDOWN), and the daemon exits with code 0. The watchdog doesn't restart a daemon that exits with 0, so it ends, and the scheduled task ends with it.flock stopwaits up to a minute for the daemon process to exit. If it doesn't, or the daemon is older and has no stop call, it falls back to whatflock restartdoes (schtasks /End).flock startuses the existingrunTask.macOS (not tested):
launchctl bootoutstops the agent (SIGTERM, so a clean shutdown) andlaunchctl bootstraploads it again. The plist stays in LaunchAgents, so it loads at the next login. The bootstrap retry loop moved frominstallServiceintobootstrapAgentso both use it.Linux (not tested):
systemctl stop/systemctl startonflock@<user>.service, which the existing polkit rule already allows. The unit stays enabled.Windows tray
flock stop, the same way Restart runsflock restart.Docs
docs/cli.mdlists the new commands.docs/installation.mdgets a short "Stopping Flock" section.windows/README.mdgets a line in the first-run checklist.I left out renaming "Quit Flock" on Windows and Linux (point 3 of the issue) to keep this PR focused. I can send it separately if you'd like.
Testing
Automated:
go vetpasses for windows, darwin and linux (amd64).go test ./...passes on Windows 11, including the newTestStopShutsTheDaemonDown(api) andTestStopEndsRun(daemon).windows/build.ps1passes: Flock.Kit.Tests 151/151, Flock.Tray.Tests 239/239.Manual, on Windows 11 with a real install (MySQL 8.4, PostgreSQL 18, Valkey 9.1, PHP 8.3 and 8.4):
flock stopwith a daemon that has an isolatedFLOCK_HOME: it stops, and the daemon process exits by itself.flock stopwith the scheduled task: MySQL's error log shows "Shutdown complete", PostgreSQL's log shows "database system is shut down", and the task is back to Ready. No Flock process is left and nothing restarts.flock startbrings the daemon back through the task with every service up.Not tested: