Running Atuin Daemon with Systemd Socket Activation

Tutorial on how to configure the Atuin daemon to run as a systemd user service with socket activation

Why Socket Activation Helps

With socket activation, systemd starts the Atuin daemon only when a client connects to its Unix socket, running it as an atuin-daemon user service. The daemon stays idle until a shell actually needs it, which saves resources.

This matters most on systems with slow HDDs. Because the daemon starts only on connection, the disk avoids unnecessary activity and the database is opened and closed less often. That reduces disk thrashing and latency, so shell history loads faster and feels more responsive — even on older or resource-constrained hardware. The lighter workload also prolongs the life of the HDD and keeps Atuin out of the way in daily workflows.

Prerequisites

  • Atuin installed with the executable at /bin/atuin (change path if needed).
  • Basic familiarity with systemd user services.
  • A user with UID 1000 (adjust the socket path if your UID differs).

Step 1: Configure the Systemd Socket Unit

Create the file ~/.config/systemd/user/atuin-daemon.socket. Systemd will listen on the Unix socket at /run/user/1000/atuin.sock and start the Atuin daemon when a client connects.

[Unit]
Description=Atuin Daemon Socket
PartOf=atuin-daemon.service

[Socket]
ListenStream=/run/user/1000/atuin.sock
SocketMode=0600
Accept=no

[Install]
WantedBy=sockets.target

Explanation:

  • ListenStream=/run/user/1000/atuin.sock: the path to the Unix socket.
  • SocketMode=0600: only the user can access it (UID 1000).
  • Accept=no: the listening socket is passed to the daemon. This is more efficient.

Step 2: Configure the Systemd Service Unit

Next, create the service unit. This file tells systemd how to run the Atuin daemon when the socket receives a connection.

Save this to ~/.config/systemd/user/atuin-daemon.service:

[Unit]
Description=Atuin Daemon
Requires=atuin-daemon.socket
After=atuin-daemon.socket

[Service]
Type=simple
ExecStart=/bin/atuin daemon
Restart=always
NonBlocking=true
KillMode=process
KillSignal=SIGTERM
TimeoutStopSec=5

[Install]
WantedBy=default.target
  • Explanation:
    • ExecStart=/bin/atuin daemon: Runs the Atuin daemon.
    • NonBlocking=true: Socket activation needs this to work.
    • KillMode=process and KillSignal=SIGTERM: These stop the daemon cleanly with SIGTERM.
    • TimeoutStopSec=5: This allows 10 seconds for a graceful shutdown.
    • Restart=always: If the daemon crashes, systemd starts it again.

Step 3: Enable and Start the Socket

Reload the systemd user configuration and enable the socket to start automatically:

systemctl --user daemon-reload
systemctl --user enable --now atuin-daemon.socket

Verify the socket is active:

systemctl --user status atuin-daemon.socket

Step 4: Configure Atuin Client

Point the Atuin client at the activated socket, /run/user/1000/atuin.sock. Set this in the Atuin configuration file (~/.config/atuin/config.toml) or via the corresponding environment variable if your version supports one:

[daemon]
enabled = true
systemd_socket = true

Step 5: Test the Setup

  • Run an Atuin command, such as atuin history list, to trigger a connection.
  • Check whether the daemon has started:
systemctl --user status atuin-daemon.service
  • Check that the socket exists:
ls -l /run/user/1000/atuin.sock
  • Stop the service. This confirms the daemon ends cleanly:
systemctl --user stop atuin-daemon.service

With this setup, the Atuin daemon runs as a systemd user service with socket activation. It starts only when needed and stops cleanly when no longer in use. For more detail, see the Atuin documentation or the community forums on the Atuin GitHub.

Troubleshooting

  • Logs: Check the logs for errors:
journalctl --user -u atuin-daemon.service
  • Permissions: The socket and executable must be accessible to your user (UID 1000).
  • Daemon Stability: Atuin's daemon mode is experimental. Watch for SQLite conflicts or crashes. This is most likely on filesystems like ZFS.
  • Restart the socket and service:
systemctl --user stop atuin-daemon.service atuin-daemon.socket
systemctl --user daemon-reload
rm /run/user/1000/atuin.sock
systemctl --user start atuin-daemon.socket