Repository navigation
feat: start with the system on Linux and macOS - #96
Merged
Merged
Conversation
- Linux: a systemd user service. Enabled when Botloft starts with the system; Restart=on-failure brings the daemon back after a crash, and KillMode=control-group ends its bots and browsers with it. - macOS: a launch agent. RunAtLoad follows the owner's choice, and KeepAlive watches a keep-alive file that starting creates and stopping (or a clean exit) deletes, since a plain KeepAlive would also start it at every sign-in. - Task arguments are a list; Windows quotes them for its command line. - Messages name what starts the daemon on each system. Spec 14.1 describes both.
…rvice manager Runs only with BOTLOFT_SERVICE_TEST=1, which CI sets on its Ubuntu runner (with a lingering user manager) and its macOS runner.
…hen it fails The step also stops after 10 minutes instead of hanging the runner.
On the macOS runner a launchctl call hung the install for 10 minutes. Each call now gives up after 30 s and says which one it was. The service test keeps its data folder under the home folder: the Linux runner's /tmp is its own, and systemd answered 203/EXEC for a binary there.
It was written with fs::write, which leaves no execute bit: systemd answered 203/EXEC and launchd never started it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Third slice of Linux/macOS support (spec 18, item 8):
botloftd service install|status|restart|stop|uninstallwork off Windows, so the daemon starts at sign-in and comes back after a crash.Linux: systemd user service
~/.config/systemd/user/botloft.service(botloft-<hash>.servicefor another data folder, like the Windows task name).Type=exec,Restart=on-failure(RestartSec=5),KillMode=control-group,TimeoutStopSec=20andWantedBy=default.target.systemctl --user enable(ordisable).service stop) exits cleanly and stays stopped.KillMode=control-groupends the bots and browsers with the daemon, which closes the orphan gap left by slice 2 on Linux.macOS: launch agent
~/Library/LaunchAgents/io.github.httpsphl.botloft.daemon[-<hash>].plist, ingui/<uid>.RunAtLoadfollows the owner's choice.KeepAliveisPathStateon<home>/run/keep-alive, because a plainKeepAlive(orSuccessfulExit) would also start it at every sign-in:install,restart, and the daemon started by the agent;bootout,bootstrap,kickstart). Stopping deletes the file and sendsSIGTERM.Shared
TaskDefinition.argumentsis a list now; Windows quotes it for its command line (same output as before, tested).sign_in_idstays empty off Windows: neither systemd nor launchd starts the daemon at a new sign-in unless the owner chose it, so no new-sign-in check is needed.Tests
%and$, XML escaping, labels. Both modules build on every Unix, so the launchd tests also run on Linux.tests/service.rsruns against the real systemd and launchd in CI only (BOTLOFT_SERVICE_TEST=1):kill -9it and see it come back;service stop, then check it stays down for 15 s;loginctl enable-lingerfor a user manager.Still missing
On macOS, launchd only kills the daemon's own process group, so a bot's browser outlives a daemon crash. A sweep at start comes next.
Manual test (not done yet)
service installkill -9the daemon and see it back within about 10 s.What the real service managers showed (fixed here)
<home>/binhad no execute bit off Windows. It was written withfs::write, so systemd answered203/EXECand launchd never started it. It is now0755, with a test.launchctlcall hung the install for 10 minutes on the macOS runner. Everysystemctlandlaunchctlcall now gives up after 30 s and says which one it was.kill -9, stays down afterstop, restart, uninstall.