You are not logged in.

#1 2014-11-02 09:55:06

Napaim
Member
From: Scotland
Registered: 2009-03-09
Posts: 26

Stuck writing a unit file which depends on a device

I have written the following:

[Unit]
Description=Resets the repeat delay in Xorg if the keyboard is re-attached
Requires=dev-daskeyboard.device
Wants=dev-daskeyboard.device graphical.target xlogin@.service
After=graphical.target
BindsTo=dev-daskeyboard.device

[Service]
Type=oneshot
ExecStart=/usr/bin/xset r rate 160
ExecStart=/usr/bin/xmodmap /mnt/old/home/napalm/.xmodmaprc
RemainAfterExit=yes

It's a unit service in ~/.config/systemd/user and I'd like it to run any time the keyboard is unplugged and plugged back in *or* any time graphical.target is met (startx is run for example, or xlogin is used in my case).

Can anybody point me as to why it isn't working?

Just to clarify if I run the following then the commands are run correctly

systemctl --user start keyboard-rate.service]

Offline

#2 2014-11-02 15:59:48

berbae
Member
From: France
Registered: 2007-02-12
Posts: 1,304

Re: Stuck writing a unit file which depends on a device

Napaim wrote:

*or* any time graphical.target is met (startx is run for example, or xlogin is used in my case)

For this part of your request, it's easy to obtain by adding your 'xset' and 'xmodmap' commands in your .xinitrc file.

I'd like it to run any time the keyboard is unplugged and plugged back in

I presume you mean you want the service to run when the keyboard is plugged in (it's not quite clear).
It's also not clear how you reach graphical.target running startx or xlogin: be more precise how you do that please.

"why it isn't working?" Because it is not the way to do that.

First you need to be sure systemd creates a 'dev-daskeyboard.device' when you plug the keyboard in.
For that to occur the udev device needs to be tagged with TAG+="systemd";
so you need to write a udev rule matching your keyboard to add the tag and with:
ENV{SYSTEMD_USER_WANTS}="<your service name>" at the end;
your service doesn't need all the 'Requires', 'Wants' and 'Bindsto' lines.

The udev rule should be triggered each times the keyboard is plugged in and systemd should then starts the service with the commands you wish to run on it.

Last edited by berbae (2014-11-03 10:15:31)

Offline

Board footer

Powered by FluxBB