1

The stock systemd user service file for emacs 29.1 looks like this:

[Unit]
Description=Emacs text editor
Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/

[Service]
Type=notify
ExecStart=/usr/bin/emacs --fg-daemon
# ExecStop=/usr/bin/emacsclient --eval "(kill-emacs)"

# Emacs will exit with status 15 after having received SIGTERM, which
# is the default "KillSignal" value systemd uses to stop services.
SuccessExitStatus=15

# The location of the SSH auth socket varies by distribution, and some
# set it from PAM, so don't override by default.
# Environment=SSH_AUTH_SOCK=%t/keyring/ssh
Restart=on-failure

[Install]
WantedBy=default.target

However, after my computer starts up and I login, and try to run emacsclient -c, nothing happens and journalctl -u emacs -f --user contains an error log:

Authorization required, but no authorization protocol specified

After a restart of emacs (systemctl --user restart emacs), there is no problem in starting emacs, and the emacsclient window opens up as expected. However, after a reboot, the same problem happens - clearly having to restart emacs immediately up login defeats the purpose of setting it up as a systemd user service.

After various googling, I ended up on https://www.emacswiki.org/emacs/EmacsAsDaemon#h5o-19 which says that we need to ensure emacs is started up after Gnome by adding these lines:

[Unit]
[email protected]
[email protected]

The problem is that Ubuntu 22.04+ (currently running 23.10) does not have a [email protected] unit. I've tried various things like gdm.service, user@%U.service instead of gnome shell in the above section and nothing seems to work. What's the right way here?

I've also had a look at Systemd starts emacs daemon without XAUTHORITY environment variable after upgrading to Fedora 37 that mentions the same problem on gnome/x11/fedora with a slightly different solution, but that doesnt work for Gnome/Wayland/Ubuntu combination.

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.