You are not logged in.
Hey,
I recently got a USB Xbox 360 Controller and set it up using antimicro and the kernel's xpad driver. Now, I want to start antimicro in the background, when I plug the controller in and stop antimicro when I unplug it.
Is there a more elegant way than running a bash script at startup which periodically checks lsusb's output and acts accordingly?
## command to run when plugged in
/usr/bin/antimicro --no-tray --hidden
## command to run when unplugged
/usr/bin/pkill antimicro
[klemens@arch-pc ~]$ lsusb | grep Xbox
Bus 003 Device 012: ID 045e:028e Microsoft Corp. Xbox360 ControllerOffline
A udev rule: https://wiki.archlinux.org/index.php/Ud … udev_rules
Offline
[klemens@arch-pc]$ cat /etc/udev/rules.d/60-xbox-controller.rules
SUBSYSTEMS=="usb", ATTRS{idVendor}=="045e", ATTRS{idProduct}=="028e", ACTION=="add", SYMLINK+="xbox", RUN+="/usr/bin/antimicro --no-tray --hidden"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="045e", ATTRS{idProduct}=="028e", ACTION=="remove", SYMLINK-="xbox", RUN+="/usr/bin/pkill antimicro"I created this one, but it has no effect. I read through the pages but can't figure out why, can you help me?
Last edited by klenamenis (2014-11-21 00:32:02)
Offline
Don't use RUN, use SYSTEMD_WANTS and a service file. See `man systemd.device`.
Offline
OK, I got the reason why not to use the RUN key, but also got confused using a systemd unit. So far, this is it:
[klemens@arch-pc ~]$ cat /etc/udev/rules.d/60-xbox-controller.rules /etc/systemd/system/dev-xbox-{in,out}.device
SUBSYSTEMS=="usb", ATTRS{idVendor}=="045e", ATTRS{idProduct}=="028e", ACTION=="add", SYMLINK+="xbox", ENV{SYSTEMD_WANTS}=="dev-xbox-in.device"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="045e", ATTRS{idProduct}=="028e", ACTION=="remove", SYMLINK-="xbox", ENV{SYSTEMD_WANTS}=="dev-xbox-out.device"
[Unit]
Description=Xbox Controller
[Service]
ExecStart=/usr/bin/antimicro --no-tray --hidden
[Unit]
Description=Xbox Controller
[Service]
ExecStart=/usr/bin/pkill antimicroDo I have to use service units? (How) can I put this into a single unit with ExecStart and ExecStop? Obviously, this way it's not working...
Offline