Systemd-user-service to enable keyboard gives no error but doesn't work
0
votes
2
answers
173
views
I have a bad laptop keyboard and a much better Lily58, so I wrote a bash-script to be able to disable my laptop keyboard so I can place the Lily58 on it and re-enable it after. But when I disable the laptop keyboard, it stays disabled if I put the laptop in suspension while I would prefer it to be automatically re-enabled on resume. So I wrote a short bash script
#!/bin/bash
fconfig="/home/alex/.keyboard"
id=$(xinput | grep AT | sed -n '2,2p' | awk '{print $7}' | sed 's/[^0-9]*//g')
if [ -f $fconfig ]; then
read -r var $fconfig
fi
fi
This checks whether "disabled" is in the file /home/alex/.keyboard
that tracks whether the keyboard is enabled, and if so runs xinput
to re-enable using the id it got by sifting through the output of xinput
in the manner used in the definition of id
, then set /home/alex/.keyboard
to enabled
. This works as it should when I trigger the bash-script from the terminal, but when I start the systemd-service
[Unit]
Description=This service enables your keyboard after suspension
PartOf=graphical-session.target
[Service]
Type=oneshot
ExecStart=/home/alex/bash/enable-keyboard
[Install]
WantedBy=multi-user.target
that I want to run after suspend, it sets /home/alex/.keyboard
to enabled
but does not actually re-enable my keyboard. Moreover, journalctl -xeu enable-keyboard.service
indicates no error:
Jul 17 22:16:25 gentoolaptop systemd: Starting This service enables your keyboard after suspension.
░░ Subject: A start job for unit UNIT has begun execution
░░ Defined-By: systemd
░░ Support: https://gentoo.org/support/
░░
░░ A start job for unit UNIT has begun execution.
░░
░░ The job identifier is 8969.
Jul 17 22:16:25 gentoolaptop systemd: Finished This service enables your keyboard after suspension.
░░ Subject: A start job for unit UNIT has finished successfully
░░ Defined-By: systemd
░░ Support: https://gentoo.org/support/
░░
░░ A start job for unit UNIT has finished successfully.
░░
░░ The job identifier is 8969.
What is going wrong?
Edit: If I put a clause into the script to print the output of xinput
into a file, the output consists of one empty line.
Edit: the output of systemctl --user status dbus.socket dbus.service
is
● dbus.socket - D-Bus User Message Bus Socket
Loaded: loaded (/usr/lib/systemd/user/dbus.socket; static)
Active: active (running) since Thu 2024-07-18 17:22:54 CEST; 5 days ago
Triggers: ● dbus.service
Listen: /run/user/1000/bus (Stream)
Tasks: 0 (limit: 47295)
Memory: 4.0K (peak: 1.5M)
CPU: 8ms
CGroup: /user.slice/user-1000.slice/user@1000.service/app.slice/dbus.socket
Jul 18 17:22:54 gentoolaptop systemd: Starting D-Bus User Message Bus Socket...
Jul 18 17:22:54 gentoolaptop systemd: Listening on D-Bus User Message Bus Socket.
● dbus.service - D-Bus User Message Bus
Loaded: loaded (/usr/lib/systemd/user/dbus.service; static)
Active: active (running) since Thu 2024-07-18 17:22:54 CEST; 5 days ago
TriggeredBy: ● dbus.socket
Docs: man:dbus-daemon(1)
Main PID: 897 (dbus-daemon)
Tasks: 1 (limit: 47295)
Memory: 1.0M (peak: 1.7M)
CPU: 252ms
CGroup: /user.slice/user-1000.slice/user@1000.service/session.slice/dbus.service
└─897 /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
Jul 23 16:55:45 gentoolaptop dbus-daemon: [session uid=1000 pid=897 pidfd=5] Activating via systemd: service name='org.freedesktop.Notifications' unit='dunst.service' requested by ':1.149' (uid=1000 pid=105378 comm="/bin/dunstify Battery <80 Battery under 80%.")
Jul 23 17:11:00 gentoolaptop dbus-daemon: [session uid=1000 pid=897 pidfd=5] Failed to activate service 'org.freedesktop.Notifications': timed out (service_start_timeout=120000ms)
Jul 23 17:19:31 gentoolaptop dbus-daemon: [session uid=1000 pid=897 pidfd=5] Activating via systemd: service name='org.freedesktop.Notifications' unit='dunst.service' requested by ':1.152' (uid=1000 pid=106706 comm="/bin/dunstify Battery <80 Battery under 80%.")
Jul 23 17:21:31 gentoolaptop dbus-daemon: [session uid=1000 pid=897 pidfd=5] Failed to activate service 'org.freedesktop.Notifications': timed out (service_start_timeout=120000ms)
Jul 23 17:30:31 gentoolaptop dbus-daemon: [session uid=1000 pid=897 pidfd=5] Activating via systemd: service name='org.freedesktop.Notifications' unit='dunst.service' requested by ':1.153' (uid=1000 pid=108520 comm="/bin/dunstify Battery <80 Battery under 80%.")
Jul 23 17:32:31 gentoolaptop dbus-daemon: [session uid=1000 pid=897 pidfd=5] Failed to activate service 'org.freedesktop.Notifications': timed out (service_start_timeout=120000ms)
Jul 24 14:15:05 gentoolaptop dbus-daemon: [session uid=1000 pid=897 pidfd=5] Activating via systemd: service name='org.freedesktop.Notifications' unit='dunst.service' requested by ':1.164' (uid=1000 pid=126615 comm="/bin/dunstify Battery <80 Battery under 80%.")
Jul 24 14:17:05 gentoolaptop dbus-daemon: [session uid=1000 pid=897 pidfd=5] Failed to activate service 'org.freedesktop.Notifications': timed out (service_start_timeout=120000ms)
Jul 24 14:26:05 gentoolaptop dbus-daemon: [session uid=1000 pid=897 pidfd=5] Activating via systemd: service name='org.freedesktop.Notifications' unit='dunst.service' requested by ':1.165' (uid=1000 pid=127823 comm="/bin/dunstify Battery <80 Battery under 80%.")
Jul 24 14:28:05 gentoolaptop dbus-daemon: [session uid=1000 pid=897 pidfd=5] Failed to activate service 'org.freedesktop.Notifications': timed out (service_start_timeout=120000ms)
The output of ls -l /run/user/*/bus
is
srw-rw-rw- 1 alex alex 0 2024-07-18 17:22 /run/user/1000/bus
.
Asked by Alexander Praehauser
(221 rep)
Jul 17, 2024, 08:30 PM
Last activity: Jul 24, 2024, 04:26 PM
Last activity: Jul 24, 2024, 04:26 PM