Unix & Linux Asked on December 26, 2021
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:
[Unit]
Description=Simple X Hotkey Daemon
Documentation=man:sxhkd(1)
BindsTo=display-manager.service
After=display-manager.service
[Service]
ExecStart=/usr/bin/sxhkd
ExecReload=/usr/bin/kill -SIGUSR1 $MAINPID
[Install]
WantedBy=graphical.target
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.
Edit:
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
?
Edit2:
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.
Edit3:
More details on the steps I followed here: https://bbs.archlinux.org/viewtopic.php?id=257626&p=2
The approach you outline is not possible, or at least, not that I know of. Consider the following counter-example: if you have a multi-head setup, you will login twice. Your systemd
will have started up one copy of your hot key daemon. Now, one of the two users of your system presses a hot key. Who gets the result on their screen? ;)
Therefore, the best way is to have the session start the hotkey daemon. The simple way is to use the startup script of your window manager, as you've done before. The more modern way would be to have some kind of user session thing manage this, and this really depends on the setup of your system and your window manager. In my experience this is always a bit hit or miss and not very well documented, whereas startup scripts are pretty simple.
One example of how to write a dbus service file can be seen here: https://serverfault.com/a/906224/107282. While the daemon you mentioned doesn't require dbus, it should allow it to start at the proper time with a configured DISPLAY
variable.
Answered by Michel on December 26, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP