Repository navigation
docs(linux): add systemd user-service autostart guide #189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TimeToBuildBob
wants to merge
4
commits into
ActivityWatch:master
Choose a base branch
from
TimeToBuildBob:docs/linux-systemd-user-services
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+185
−1
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cc41c7b
docs(linux): add systemd user-service autostart guide
TimeToBuildBob b109608
docs(linux): nest systemd guide under getting started
TimeToBuildBob 18d268c
docs(linux): point X11 watcher units at the session environment check
TimeToBuildBob d7628d9
docs(linux): retry the Wayland readiness wait via ExecStart
TimeToBuildBob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,4 +72,4 @@ Indices and tables | |
|
|
||
| * :ref:`genindex` | ||
| * :ref:`modindex` | ||
| * :ref:`search` | ||
| * :ref:`search` | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| .. _systemd-autostart: | ||
|
|
||
| *********************************** | ||
| Autostart on Linux with systemd | ||
| *********************************** | ||
|
|
||
| Linux systems that use systemd can run ActivityWatch as user services. This | ||
| avoids the tray application, keeps logs in the user journal, and restarts a | ||
| component if it fails. Do not run these services and ``aw-qt`` at the same | ||
| time: disable the existing ActivityWatch desktop autostart entry first. | ||
|
|
||
| The examples assume that the extracted ActivityWatch directory is at | ||
| ``~/.local/opt/activitywatch``. Adjust the ``ExecStart`` paths if you installed | ||
| it elsewhere. Create the unit directory with:: | ||
|
|
||
| mkdir -p ~/.config/systemd/user | ||
|
|
||
| X11: server and default watchers | ||
| ================================ | ||
|
|
||
| The default AFK and window watchers support X11. Create | ||
| ``~/.config/systemd/user/activitywatch-server.service``: | ||
|
|
||
| .. code-block:: ini | ||
|
|
||
| [Unit] | ||
| Description=ActivityWatch server | ||
| Documentation=https://docs.activitywatch.net/ | ||
| After=graphical-session.target | ||
| PartOf=graphical-session.target | ||
|
|
||
| [Service] | ||
| # aw-server-rust sends READY=1 via sd_notify, so Type=notify is correct: | ||
| # the unit becomes active only once the HTTP server is actually listening. | ||
| Type=notify | ||
| ExecStart=%h/.local/opt/activitywatch/aw-server-rust/aw-server-rust | ||
| Restart=on-failure | ||
| RestartSec=5 | ||
|
|
||
| [Install] | ||
| WantedBy=graphical-session.target | ||
|
|
||
| Create ``~/.config/systemd/user/activitywatch-afk.service``: | ||
|
|
||
| .. code-block:: ini | ||
|
|
||
| [Unit] | ||
| Description=ActivityWatch AFK watcher | ||
| Documentation=https://docs.activitywatch.net/ | ||
| Requires=activitywatch-server.service | ||
| After=graphical-session.target activitywatch-server.service | ||
| PartOf=graphical-session.target | ||
|
|
||
| [Service] | ||
| Type=simple | ||
| ExecStart=%h/.local/opt/activitywatch/aw-watcher-afk/aw-watcher-afk | ||
| Restart=on-failure | ||
| RestartSec=5 | ||
| KillSignal=SIGINT | ||
|
|
||
| [Install] | ||
| WantedBy=graphical-session.target | ||
|
|
||
| Create ``~/.config/systemd/user/activitywatch-window.service``: | ||
|
|
||
| .. code-block:: ini | ||
|
|
||
| [Unit] | ||
| Description=ActivityWatch X11 window watcher | ||
| Documentation=https://docs.activitywatch.net/ | ||
| Requires=activitywatch-server.service | ||
| After=graphical-session.target activitywatch-server.service | ||
| PartOf=graphical-session.target | ||
|
|
||
| [Service] | ||
| Type=simple | ||
| ExecStart=%h/.local/opt/activitywatch/aw-watcher-window/aw-watcher-window | ||
| Restart=on-failure | ||
| RestartSec=5 | ||
| KillSignal=SIGINT | ||
|
|
||
| [Install] | ||
| WantedBy=graphical-session.target | ||
|
|
||
| Then validate and start the units:: | ||
|
|
||
| systemd-analyze --user verify ~/.config/systemd/user/activitywatch-*.service | ||
| systemctl --user daemon-reload | ||
| systemctl --user enable --now activitywatch-server.service activitywatch-afk.service activitywatch-window.service | ||
|
|
||
| The watchers need ``DISPLAY`` (and usually ``XAUTHORITY``) in the user manager's | ||
| environment. If they keep restarting, run the environment check described in the | ||
| GNOME/Wayland section below; it applies to X11 as well. | ||
|
|
||
| GNOME/Wayland: awatcher bundle | ||
| ================================ | ||
|
|
||
| The default Linux watchers require X11. On GNOME/Wayland, install the | ||
| `Focused Window D-Bus extension <https://extensions.gnome.org/extension/5592/focused-window-d-bus/>`_ | ||
| and the bundled `awatcher <https://github.com/2e3s/awatcher/releases>`_ package. | ||
| The bundle supplies its own Rust server and replaces both default watchers, so | ||
| do not start the three X11 services above. | ||
|
|
||
| The current bundle installs the executable as ``awatcher``. Older releases may | ||
| call it ``awatcher-bundle``; check with ``command -v awatcher || command -v | ||
| awatcher-bundle`` and adjust ``ExecStart`` if needed. | ||
|
|
||
| Create ``~/.config/systemd/user/activitywatch-wayland.service``: | ||
|
|
||
| .. code-block:: ini | ||
|
|
||
| [Unit] | ||
| Description=ActivityWatch for GNOME/Wayland (awatcher bundle) | ||
| Documentation=https://docs.activitywatch.net/ | ||
| After=graphical-session.target | ||
| PartOf=graphical-session.target | ||
| StartLimitIntervalSec=300 | ||
| StartLimitBurst=5 | ||
|
|
||
| [Service] | ||
| Type=simple | ||
| # Wait up to 30 seconds for the GNOME extension's D-Bus interface, then | ||
| # exec the watcher. The wait lives in ExecStart, not ExecStartPre: a failed | ||
| # ExecStartPre leaves the unit failed and is NOT retried by Restart=, while | ||
| # a main-process failure is. | ||
| ExecStart=/bin/sh -c 'i=0; while [ $$i -lt 30 ]; do /usr/bin/busctl --user introspect org.gnome.Shell /org/gnome/shell/extensions/FocusedWindow org.gnome.shell.extensions.FocusedWindow >/dev/null 2>&1 && break; i=$$((i + 1)); sleep 1; done; exec /usr/bin/awatcher -vv --no-tray' | ||
| Restart=on-failure | ||
| RestartSec=10 | ||
|
|
||
| [Install] | ||
| WantedBy=graphical-session.target | ||
|
|
||
| Do not hardcode ``DISPLAY`` or ``WAYLAND_DISPLAY=wayland-0``: display names | ||
| vary, and a graphical session should import the correct values into the user | ||
| manager. Check them with:: | ||
|
|
||
| systemctl --user show-environment | grep -E '^(DISPLAY|WAYLAND_DISPLAY|XAUTHORITY)=' | ||
|
|
||
| If the values are missing, import the current session before starting the | ||
| service:: | ||
|
|
||
| dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY XAUTHORITY | ||
|
|
||
| Then validate and start the service:: | ||
|
|
||
| systemd-analyze --user verify ~/.config/systemd/user/activitywatch-wayland.service | ||
| systemctl --user daemon-reload | ||
| systemctl --user enable --now activitywatch-wayland.service | ||
|
|
||
| Verify and troubleshoot | ||
| ======================== | ||
|
|
||
| The server should answer on ``127.0.0.1:5600``:: | ||
|
|
||
| curl --fail http://127.0.0.1:5600/api/0/info | ||
|
|
||
| Inspect status and logs with:: | ||
|
|
||
| systemctl --user status 'activitywatch-*' | ||
| journalctl --user -u 'activitywatch-*' --boot | ||
|
|
||
| After changing a unit, run ``systemctl --user daemon-reload`` and restart it. | ||
| To test the X11 services without touching your normal database or server, add | ||
| ``--testing --port 5660`` to their ``ExecStart`` commands temporarily. | ||
| Stop and disable a setup with:: | ||
|
|
||
| systemctl --user disable --now activitywatch-server.service activitywatch-afk.service activitywatch-window.service | ||
| systemctl --user disable --now activitywatch-wayland.service | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.