#StackBounty: #systemd #sxhkd Can't start sxhkd as a systemd service

Bounty: 100

I’m using bspwm on my Arch Linux install and I need to run the sxhkd hotkey daemon to launch my applications.

Up to now, the launch script was in my .config/bspwm/bspwmrc (which is a simple bash script file):

# Keyboard bindings manager
pkill sxhkd
sxhkd -m 1&

The -m 1 argument is there because I don’t have a qwerty keyboard.

The bspwmrc script is executed by my display manager, LightDM, when it auto logs me in. So far so good.

Reading the Arch Wiki, I realized I could start sxhkd with Systemd directly. There’s even a link to a sample service file; which contains:

Description=Simple X Hotkey Daemon

ExecReload=/usr/bin/kill -SIGUSR1 $MAINPID


So I wondered, why not? And copied the sxhkd.service file to /etc/systemd/system (after adding the -m 1 argument), enabled the service with sudo systemctl enable sxhkd, commented the lines in the bspwmrc script, and restarted.

Alas, that does not work. When typing systemctl status sxhkd, I get this error message:

Warning: The unit file, source configuration file or drop-ins of sxhkd.service changed on disk. Run 'systemctl daemon-rel>
● sxhkd.service - Simple X Hotkey Daemon
     Loaded: loaded (/etc/systemd/system/sxhkd.service; enabled; vendor preset: disabled)
     Active: failed (Result: exit-code) since Fri 2020-07-24 10:29:05 CEST; 14min ago
       Docs: man:sxhkd(1)
   Main PID: 662 (code=exited, status=1/FAILURE)

Jul 24 10:29:05 Solgaleo systemd[1]: Started Simple X Hotkey Daemon.
Jul 24 10:29:05 Solgaleo sxhkd[662]: Can't open display.
Jul 24 10:29:05 Solgaleo systemd[1]: sxhkd.service: Main process exited, code=exited, status=1/FAILURE
Jul 24 10:29:05 Solgaleo systemd[1]: sxhkd.service: Failed with result 'exit-code'.

My understanding is that Can't open display means that sxhkd starts too early… and I don’t know why, or how to fix this.

I know I could just go back to my previous configuration, but if there’s something on the Arch Wiki that does not work, I’d rather find out if it’s my fault or if the wiki needs to be updated.


Further investigation indicates that running sxhkd as root cannot work.

Here is what I changed:

I moved the sxhkd.service file from /etc/systemd/system to /etc/systemd/user and enabled it via the systemctl --user enable sxhkd command.

This still does not work, but with a different error message:

Failed to start sxhkd.service: Unit display-manager.service not found. 

Typing systemctl status display-manager gives:

● lightdm.service - Light Display Manager
     Loaded: loaded (/usr/lib/systemd/system/lightdm.service; enabled; vendor preset: disabled)
     Active: active (running) since Sat 2020-07-25 11:11:07 CEST; 10min ago
       Docs: man:lightdm(1)
   Main PID: 602 (lightdm)
      Tasks: 4 (limit: 38412)
     Memory: 63.7M
     CGroup: /system.slice/lightdm.service
             ├─602 /usr/bin/lightdm
             └─666 /usr/lib/Xorg -bs -core :0 -seat seat0 -auth /run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch

Jul 25 11:11:05 Solgaleo systemd[1]: Starting Light Display Manager...
Jul 25 11:11:07 Solgaleo lightdm[602]: Error getting user list from org.freedesktop.Accounts: GDBus.Error:org.freedesktop>
Jul 25 11:11:07 Solgaleo systemd[1]: Started Light Display Manager.
Jul 25 11:11:08 Solgaleo lightdm[670]: pam_succeed_if(lightdm-autologin:auth): requirement "user ingroup autologin" was m>
Jul 25 11:11:08 Solgaleo lightdm[670]: Error getting user list from org.freedesktop.Accounts: GDBus.Error:org.freedesktop>
Jul 25 11:11:08 Solgaleo lightdm[670]: pam_unix(lightdm-autologin:session): session opened for user ben by (uid=0)
lines 1-17/17 (END)

Which means display-manager is properly running. Maybe it can’t be seen by a service launched with --user?


The BindsTo and After are actually not necessary: the service is started as a user, so after the user session has been started. But if I remove them, the service does not start at all upon startup. It works great if I start it manually though.


More details on the steps I followed here: https://bbs.archlinux.org/viewtopic.php?id=257626&p=2

Get this bounty!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.