From cc41c7bf7921400a024716d76798042f08464803 Mon Sep 17 00:00:00 2001 From: Bob Date: Fri, 2 Oct 2026 02:59:47 +0000 Subject: [PATCH 1/4] docs(linux): add systemd user-service autostart guide Git-Session-Id: a4b3 --- src/getting-started.rst | 4 + src/index.rst | 3 +- src/running-on-gnome.rst | 4 + src/systemd-autostart.rst | 161 ++++++++++++++++++++++++++++++++++++++ src/watchers.rst | 3 + 5 files changed, 174 insertions(+), 1 deletion(-) create mode 100644 src/systemd-autostart.rst diff --git a/src/getting-started.rst b/src/getting-started.rst index de4e48b..f978557 100644 --- a/src/getting-started.rst +++ b/src/getting-started.rst @@ -149,3 +149,7 @@ A duplicate entry is harmless on its own: both apps only allow one running insta Window managers and desktop environments that don't support `XDG Autostart `_ ignore ``~/.config/autostart``. There, start ``aw-qt`` (or ``aw-tauri``) from wherever you keep your startup commands, or use `dex `_ to run XDG autostart entries. + + On Linux with systemd, you can instead run the server and watchers as + :doc:`user services `. This also covers a reliable + GNOME/Wayland setup without ``aw-qt``. diff --git a/src/index.rst b/src/index.rst index c6bdb63..a41085a 100644 --- a/src/index.rst +++ b/src/index.rst @@ -26,6 +26,7 @@ Table of contents directories features watchers + systemd-autostart faq syncing migrating @@ -72,4 +73,4 @@ Indices and tables * :ref:`genindex` * :ref:`modindex` -* :ref:`search` \ No newline at end of file +* :ref:`search` diff --git a/src/running-on-gnome.rst b/src/running-on-gnome.rst index 01938bf..99d20a5 100644 --- a/src/running-on-gnome.rst +++ b/src/running-on-gnome.rst @@ -3,6 +3,10 @@ Running on GNOME The ``aw-qt`` tray icon works on GNOME if you install the `AppIndicator and KStatusNotifierItem Support `_ extension (it ships by default in some distributions such as Ubuntu). If you can't or don't want to use it, read on. +For GNOME/Wayland, prefer the :doc:`systemd setup `, which +waits for the required D-Bus interface instead of relying on a fixed startup +delay. + As an alternative for users of GNOME 3 and other desktop environments that don't support app trays, or simply to avoid depending on Qt, you can place two simple workaround scripts in your ActivityWatch install folder: :code:`start.sh`: diff --git a/src/systemd-autostart.rst b/src/systemd-autostart.rst new file mode 100644 index 0000000..4f15ff2 --- /dev/null +++ b/src/systemd-autostart.rst @@ -0,0 +1,161 @@ +.. _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] + 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 + +GNOME/Wayland: awatcher bundle +================================ + +The default Linux watchers require X11. On GNOME/Wayland, install the +`Focused Window D-Bus extension `_ +and the bundled `awatcher `_ 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. + # This is reliable across machines; a fixed sleep is not. + ExecStartPre=/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 && exit 0; i=$$((i + 1)); sleep 1; done; exit 1' + ExecStart=/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 diff --git a/src/watchers.rst b/src/watchers.rst index ba682f0..02d3a04 100644 --- a/src/watchers.rst +++ b/src/watchers.rst @@ -23,6 +23,9 @@ Watches the active window, its title, and application name. - :gh:`2e3s/awatcher` - A compiled watcher for X11 and Wayland to replace default window and AFK watchers, by :gh-user:`2e3s`. - :gh:`bobvanderlinden/aw-watcher-window-hyprland` - A window watcher for Hyprland, by :gh-user:`bobvanderlinden`. +For a systemd-managed X11 setup or a GNOME/Wayland setup using the awatcher +bundle, see :doc:`systemd-autostart`. + Browser watchers ---------------- From b1096085472ede1a172b59322a9b160c3e2414fd Mon Sep 17 00:00:00 2001 From: Bob Date: Sat, 10 Oct 2026 14:58:41 +0000 Subject: [PATCH 2/4] docs(linux): nest systemd guide under getting started Git-Session-Id: 731acb7e-b917-55e8-90d6-7f7cf8c5c29c --- src/getting-started.rst | 5 +++++ src/index.rst | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/getting-started.rst b/src/getting-started.rst index f978557..cb7bded 100644 --- a/src/getting-started.rst +++ b/src/getting-started.rst @@ -71,6 +71,11 @@ If you want more advanced ways to run ActivityWatch (including running it withou Autostart ========= +.. toctree:: + :hidden: + + systemd-autostart + Both desktop apps, aw-qt and the newer aw-tauri, have a **Start at login** checkbox in their tray menu. Ticking it registers ActivityWatch with your operating system so it starts when you log in; unticking it removes that registration. The change takes effect from your next login. diff --git a/src/index.rst b/src/index.rst index a41085a..a3af398 100644 --- a/src/index.rst +++ b/src/index.rst @@ -26,7 +26,6 @@ Table of contents directories features watchers - systemd-autostart faq syncing migrating From 18d268c46b34af188f0047da638f711f668133b3 Mon Sep 17 00:00:00 2001 From: Bob Date: Tue, 24 Nov 2026 07:59:27 +0000 Subject: [PATCH 3/4] docs(linux): point X11 watcher units at the session environment check Git-Session-Id: b9c03d55-275e-466b-9930-22dc06ea4a45 --- src/systemd-autostart.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/systemd-autostart.rst b/src/systemd-autostart.rst index 4f15ff2..0663b0f 100644 --- a/src/systemd-autostart.rst +++ b/src/systemd-autostart.rst @@ -86,6 +86,10 @@ Then validate and start the units:: 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 ================================ From d7628d93cea65909603ccf61345c24d4d73a2d53 Mon Sep 17 00:00:00 2001 From: Bob Date: Fri, 27 Nov 2026 14:20:05 +0000 Subject: [PATCH 4/4] docs(linux): retry the Wayland readiness wait via ExecStart Git-Session-Id: 2e1756a6-47e6-480b-9da0-363aac57d2ba --- src/systemd-autostart.rst | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/systemd-autostart.rst b/src/systemd-autostart.rst index 0663b0f..94d4e75 100644 --- a/src/systemd-autostart.rst +++ b/src/systemd-autostart.rst @@ -30,6 +30,8 @@ The default AFK and window watchers support X11. Create 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 @@ -117,10 +119,11 @@ Create ``~/.config/systemd/user/activitywatch-wayland.service``: [Service] Type=simple - # Wait up to 30 seconds for the GNOME extension's D-Bus interface. - # This is reliable across machines; a fixed sleep is not. - ExecStartPre=/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 && exit 0; i=$$((i + 1)); sleep 1; done; exit 1' - ExecStart=/usr/bin/awatcher -vv --no-tray + # 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