You are not logged in.
I'm using bspwm 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][1], I realized I could start sxhkd with Systemd directly. There's even a [link][2] 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.
I tried to add the
User=ben
line in the [Service] section of the Systemd service, because there is no reason sxhkd would need to run as root (might be a security issue even, because the user could launch scripts as root via the sxhkd configuration file?) but that does not solve the problem.
Maybe this comes from LightDM not properly exporting the $DISPLAY variable? I'm not sure how to try and fix this...
[1]: https://wiki.archlinux.org/index.php/Sxhkd#Usage
[2]: https://github.com/baskerville/sxhkd/bl … kd.service
Last edited by neopium (2021-02-21 21:11:40)
Offline
You didn’t follow the wiki correctly, the user on the service is not needed, you need to autostart it as an user service on LightDM login...
For example: ‘systemctl —user start <theservice>’
Right now you are starting it WHEN LightDM inits itself, that’s waay to early....(you haven’t logged in yet)
Last edited by GaKu999 (2020-07-25 08:48:01)
Offline
Thanks for your answer.
The command ‘systemctl —user start <theservice>’ is to start the service manually. What if I want it to start automatically?
Would ‘systemctl —user enable <theservice>’ work?
I have tried `sudo systemctl --user start sxhkd` and get an error message 'Failed to connect to bus: No such file or directory'
Offline
Ok, forget about my previous post:
When you execute systemctl --user with sudo, it does not work. This needs to be executed as a user.
I moved the sxhkd.service file from /etc/systemd/system to /etc/systemd/user and enabled it via the systemctl --user enable sxhkd command. It works and gets enabled. It fails to load automatically however. When I enable it manually, it crashes with message
Failed to start sxhkd.service: Unit display-manager.service not found.
But it's there:
$ systemctl status display-manager
● 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)
Maybe it can't be accessed by the sxhkd service because it's not a user service?
Offline
That is the case, but it should not matter as it will run after the display manager anyway as that is the one that initializes your user session, so just remove the after and bindsto definitions
Offline
display-manager is a system service
Try
[Unit]
Description=Simple X Hotkey Daemon
Documentation=man:sxhkd(1)
[Service]
ExecStart=/usr/bin/sxhkd
ExecReload=/usr/bin/kill -SIGUSR1 $MAINPID
[Install]
WantedBy=graphical.target
https://wiki.archlinux.org/index.php/Sy … user_units
Edit: fuck.
Last edited by seth (2020-07-25 12:39:11)
Online
Making progress!
Using the above service file kinda works.
When I started the computer, my session loaded but when I typed super+enter key for instance (that runs a terminal), it did not do anything.
I thus changed to TTY (with ctrl-alt-F2) and could see the service was loaded... I restarted it with 'systemctl --user restart sxhkd' and switched back to my X session. sxhkd worked then... I still think there is something off with the startup time and I believe it still starts too early
Last edited by neopium (2020-07-25 12:55:37)
Offline
Do you xmodmap or setxkbmap after/with the login?
Online
Mmmh... I don't know :-D
in my .profile, I do:
xset -b
xsetroot -cursor_name left_ptr
export _JAVA_AWT_WM_NONREPARENTING=1
export PATH="$HOME/.cargo/bin:$PATH"
export PROTON_FORCE_LARGE_ADDRESS_AWARE=1
and in my .bashrc I do
#
# ~/.bashrc
#
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
PS1='[\u@\h \W]\$ '
if [ -e ~/.bashrc.aliases ] ; then
source ~/.bashrc.aliases
fi
EDITOR=/usr/bin/vi
if ! pgrep -u "$USER" ssh-agent > /dev/null; then
ssh-agent | grep -v echo >~/.ssh-agent-thing
fi
if [[ ! "$SSH_AUTH_SOCK" ]]; then
eval "$(<~/.ssh-agent-thing)"
fi
neofetch
I don't have a local .xinit file and the one in /etc/X11/xinit/xinitrc should be the default one:
#!/bin/sh
userresources=$HOME/.Xresources
usermodmap=$HOME/.Xmodmap
sysresources=/etc/X11/xinit/.Xresources
sysmodmap=/etc/X11/xinit/.Xmodmap
# merge in defaults and keymaps
if [ -f $sysresources ]; then
xrdb -merge $sysresources
fi
if [ -f $sysmodmap ]; then
xmodmap $sysmodmap
fi
if [ -f "$userresources" ]; then
xrdb -merge "$userresources"
fi
if [ -f "$usermodmap" ]; then
xmodmap "$usermodmap"
fi
# start some nice programs
if [ -d /etc/X11/xinit/xinitrc.d ] ; then
for f in /etc/X11/xinit/xinitrc.d/?*.sh ; do
[ -x "$f" ] && . "$f"
done
unset f
fi
twm &
xclock -geometry 50x50-1+1 &
xterm -geometry 80x50+494+51 &
xterm -geometry 80x20+494-0 &
exec xterm -geometry 80x66+0+0 -name login
There is also nothing of the sort in my bspwmrc file
Last edited by neopium (2020-07-25 13:12:07)
Offline
Here is a screenshot of my TTY: https://imgur.com/a/OTG6VUv
Offline
Since you're apparently using lightdm, your (global) xinitrc won't be used anyway.
https://wiki.archlinux.org/index.php/Li … on_wrapper
Seems lightdm runs setxkbmap and/or xmodmap
What happens if you just make
…
ExecStart=/usr/bin/sleep 2: /usr/bin/sxhkd
…
Online
Actually, my launch command is `/usr/bin/sxhkd -m 1`, because I have an AZERTY keyboard. Thus the 'ExecStart=/usr/bin/sleep 2: /usr/bin/sxhkd -m 1' fails because of the -m 1
Anyway, what I did was
[Unit]
Description=Simple X Hotkey Daemon
Documentation=man:sxhkd(1)
[Service]
ExecStartPre=/usr/bin/sleep 2
ExecStart=/usr/bin/sxhkd -m 1
ExecReload=/usr/bin/kill -SIGUSR1 $MAINPID
[Install]
WantedBy=graphical.target
And the result is: https://imgur.com/a/nMmTcqZ
Which basically says the service is inactive on startup and only launched when I start it manually. Are you sure about the WantedBy target in the context of a user service? It seems it doesn't trigger...
Offline
It fails because I typo'd - it's "… sleep 2; /usr/bin/…" (semicolon)
Online
I used ExectStartPre instead... It works, but when I start it manually only
Offline
What have you done to make it start automatically? Did you define graphical.target and ensure that it gets started? Or did you manually hook it into some other target?
If not, why would it be started? Remember what you learned earlier:
Maybe it can't be accessed by the sxhkd service because it's not a user service?
Offline
Mmh, I'm more confused than before :-D
My current version of the service is:
[Unit]
Description=Simple X Hotkey Daemon
Documentation=man:sxhkd(1)
[Service]
ExecStartPre=/usr/bin/sleep 2
ExecStart=/usr/bin/sxhkd -m 1
ExecReload=/usr/bin/kill -SIGUSR1 $MAINPID
[Install]
WantedBy=graphical.target
First question: Is the WantedBy line enough to start sxhkd after the graphical target?
Then to answer your question:
[ben@Solgaleo ~]$ systemctl --user status graphical.target
Unit graphical.target could not be found.
So I guess maybe I need to create a user graphical target? How do I do that?
When I list the system targets, this is what I get:
[ben@Solgaleo ~]$ systemctl list-units --type=target
UNIT LOAD ACTIVE SUB DESCRIPTION
basic.target loaded active active Basic System
cryptsetup.target loaded active active Local Encrypted Volumes
getty.target loaded active active Login Prompts
graphical.target loaded active active Graphical Interface
local-fs-pre.target loaded active active Local File Systems (Pre)
local-fs.target loaded active active Local File Systems
multi-user.target loaded active active Multi-User System
network-online.target loaded active active Network is Online
network.target loaded active active Network
paths.target loaded active active Paths
remote-fs.target loaded active active Remote File Systems
slices.target loaded active active Slices
sockets.target loaded active active Sockets
sound.target loaded active active Sound Card
swap.target loaded active active Swap
sysinit.target loaded active active System Initialization
time-set.target loaded active active System Time Set
time-sync.target loaded active active System Time Synchronized
timers.target loaded active active Timers
LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
19 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
And the user targets
[ben@Solgaleo ~]$ systemctl --user list-units --type=target
UNIT LOAD ACTIVE SUB DESCRIPTION
basic.target loaded active active Basic System
default.target loaded active active Main User Target
paths.target loaded active active Paths
sockets.target loaded active active Sockets
timers.target loaded active active Timers
LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
5 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
There's no graphical target for the user. Would using default.target work?
As far as I understand WantedBy, it means that sxhkd would be a dependency of default.target. I think I want it to be the other way around
Last edited by neopium (2020-07-25 15:18:56)
Offline
Now, this is all I've found on this subject.
It makes sense to have that keybind manager as an user service, after all it's going to be used by the user until logout, as a system service how it would be user specific?
Not every user would use the same keybindings right?
I may be wrong about this but it's what makes sense, even the wiki tells you that the way to restart it is like 'systemctl --user restart sxhkd'
Now, the default.target in my case is a symlink to multi-user.target, since I login to the linux console.
To know what is your default.target use: 'systemctl get-default'
To change the default target you need to use: 'sudo systemctl set-default graphical'
You may need to enable that service, if you made it up properly then 'systemctl --user status sxhkd' should report a disabled service.
Then you need to run: 'systemctl --user enable sxhkd' so it starts on user login, but this may be wrong...
Anyways the psd package has a service that works as an user service that needs to be enabled for the user and then it dies on logout as expected, maybe use it as example?
Someone correct me if I am wrong about something...
(oh neat @graysky is the author, never realised it lol...)
The psd service looks like this:
[Unit]
Description=Profile-sync-daemon
Documentation=man:psd(1) man:profile-sync-daemon(1)
Documentation=https://wiki.archlinux.org/index.php/Profile-sync-daemon
Wants=psd-resync.service
RequiresMountsFor=/home/
After=winbindd.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/profile-sync-daemon startup
ExecStop=/usr/bin/profile-sync-daemon unsync
[Install]
WantedBy=default.target
Obviously you don't need to use it like this, because sxhkd only makes sense for the GUI login, this service is GUI/CLI agnostic.
Last edited by GaKu999 (2020-07-25 17:09:18)
Offline
Now, this is all I've found on this subject.
It makes sense to have that keybind manager as an user service, after all it's going to be used by the user until logout, as a system service how it would be user specific?
Not every user would use the same keybindings right?I may be wrong about this but it's what makes sense, even the wiki tells you that the way to restart it is like 'systemctl --user restart sxhkd'
I agree with you here: there's no sense in sxhkd starting as root.
Now, the default.target in my case is a symlink to multi-user.target, since I login to the linux console.
To know what is your default.target use: 'systemctl get-default'
To change the default target you need to use: 'sudo systemctl set-default graphical'
My default target is... well, it depends:
[ben@Solgaleo ~]$ systemctl get-default
graphical.target
[ben@Solgaleo ~]$ systemctl --user get-default
default.target
[ben@Solgaleo ~]$ systemctl --user status default.target
● default.target - Main User Target
Loaded: loaded (/usr/lib/systemd/user/default.target; static; vendor preset: enabled)
Active: active since Sat 2020-07-25 16:44:44 CEST; 3h 7min ago
Docs: man:systemd.special(7)
Jul 25 16:44:44 Solgaleo systemd[678]: Reached target Main User Target.
So my system default target is graphical.target. But my user default target is... default.target
You may need to enable that service, if you made it up properly then 'systemctl --user status sxhkd' should report a disabled service.
Then you need to run: 'systemctl --user enable sxhkd' so it starts on user login, but this may be wrong...
This I did
Anyways the psd package has a service that works as an user service that needs to be enabled for the user and then it dies on logout as expected, maybe use it as example?
Someone correct me if I am wrong about something...
(oh neat @graysky is the author, never realised it lol...)
The psd service looks like this:[Unit] Description=Profile-sync-daemon Documentation=man:psd(1) man:profile-sync-daemon(1) Documentation=https://wiki.archlinux.org/index.php/Profile-sync-daemon Wants=psd-resync.service RequiresMountsFor=/home/ After=winbindd.service [Service] Type=oneshot RemainAfterExit=yes ExecStart=/usr/bin/profile-sync-daemon startup ExecStop=/usr/bin/profile-sync-daemon unsync [Install] WantedBy=default.target
Obviously you don't need to use it like this, because sxhkd only makes sense for the GUI login, this service is GUI/CLI agnostic.
It think what I am missing is the `After=` command. But when I listed my user targets, I don't have much choice... (see post above)
Offline
I thought I found the solution... but not really.
So I used this:
[Unit]
Description=Simple X Hotkey Daemon
Documentation=man:sxhkd(1)
[Service]
ExecStartPre=/usr/bin/sleep 2
ExecStart=/usr/bin/sxhkd -m 1
ExecReload=/usr/bin/kill -SIGUSR1 $MAINPID
[Install]
WantedBy=default.target
And it worked. So I tried:
[Unit]
Description=Simple X Hotkey Daemon
Documentation=man:sxhkd(1)
[Service]
ExecStart=/usr/bin/sxhkd -m 1
ExecReload=/usr/bin/kill -SIGUSR1 $MAINPID
[Install]
WantedBy=default.target
And it failed...
My guess is that WantedBy=default.target means my service is started *before* default.target. But what I want is for it to run *after* that target... I guess... Maybe
Offline
It seems so, even it will also attempt to start in a regular console login...
In my case the user services for GUI are started by xfce4, but they remain alive even when I stop using it...
Is there an equivalent for your GUI (your De, WM, etc...) to mimic this behavior?
To make it start every service that you need in an array or something, like pulseaudio for example?
Or if you don’t care about console login then it’s fine I guess...
Offline
It seems so, even it will also attempt to start in a regular console login...
In my case the user services for GUI are started by xfce4, but they remain alive even when I stop using it...
Is there an equivalent for your GUI (your De, WM, etc...) to mimic this behavior?
To make it start every service that you need in an array or something, like pulseaudio for example?
Or if you don’t care about console login then it’s fine I guess...
Yes there is. It's actually how I started it before I tried using Systemd.
My bspmwrc file is a shell script that is executed by lightDM once logged in (I honestly don't remember how or where I configured this). And originally, I started sxhkd within this bspwmrc script. And everything worked.
As stated at the beginning of the thread, I could go back to this behavior, but that's beyond my purpose:
- I want to understand how Systemd works in this case, I don't want to give up or work around it. I'm surely doing something wrong and it will trouble me until I find what is not working properly.
- If the Wiki is wrong, or incomplete, I want to contribute improving it
Last edited by neopium (2020-07-25 19:20:40)
Offline
In that case maybe more experimentation is needed, you can consult the systemd.unit man page to see if there’s some conditional that allows the service to distinguish if it’s being launched by a graphical login, maybe a checkup to the $DISPLAY environment variable or something relevant...
It could be useful in that use case for those that may desire such behavior, and a nice addition to the wiki.
I have not fount such conditional, the only thing I found was ExecConditional that makes the rest of the execs bail out if what’ve executed by it returns other than 0...maybe run it after sleep in order to check if it’s launched by a graphical login? Seems hacky...
Definitely there must be a better way and I’m just goofing around...
EDIT: it’s systemd.unit the one that covers most of the unit conditionals...
Last edited by GaKu999 (2020-07-25 21:05:45)
Offline
My guess is that WantedBy=default.target means my service is started *before* default.target.
No, that's where the file is installed on enabling it. It explains why enabling it failed before entirely.
I'm pretty sure it works™ but something™ still alters the keyboard config, resulting in a different keyboard map and invalidating the sxhkd key grabs.
You're using an azerty keyboard: how exactly do you configure that?
What if you go for https://wiki.archlinux.org/index.php/Xo … tion_files ?
Online
Well, I don't remember how I did configure the keyboard when I installed Arch last year... But my /etc/X11/xorg.conf.d/00-keyboard.conf file looks like this:
# Written by systemd-localed(8), read by systemd-localed and Xorg. It's
# probably wise not to edit this file manually. Use localectl(1) to
# instruct systemd-localed to update it.
Section "InputClass"
Identifier "system-keyboard"
MatchIsKeyboard "on"
Option "XkbLayout" "fr"
EndSection
Edit:
Actually, I found the script I wrote and that I used for the installation. It says:
echo "Configuring locale and time zones"
sed -i 's/#\(en_GB\.UTF-8\)/\1/' /mnt/etc/locale.gen
arch-chroot /mnt locale-gen
localectl set-x11-keymap fr
cp /etc/X11/xorg.conf.d/00-keyboard.conf /mnt/etc/X11/xorg.conf.d/00-keyboard.conf
echo "KEYMAP=fr" > /mnt/etc/vconsole.conf
Last edited by neopium (2020-07-25 20:38:35)
Offline
That should not require further xkbmap changes… however:
What if you play w/ the "-m 1" parameter? It indicates that you had to cover for at least one mapping event. Maybe
a) this is no longer the case and you can just omit the parameter
b) you're now facing 2 or more changes
Online