Re: [systemd-devel] Requiring hardware device and escaping device names
On Wed, 26.03.14 14:55, Jóhann B. Guðmundsson (johan...@gmail.com) wrote: On 03/26/2014 01:50 PM, Kai Hendry wrote: Thanks Michael for answering, :) On 26 March 2014 18:59, Michael Biebl mbi...@gmail.com wrote: 2014-03-26 3:56 GMT+01:00 Kai Hendry hen...@webconverger.com: If your daemon is not functional if the hardware is not present, I'd probably start it via a udev rule and SYSTEMD_WANTS. Do you have an example for this please? I don't quite understand why I can't I just name the device in the service file. Why does it have to be so confusing. Still don't understand the need for escaping... is there a need? The reason is when your hardware becomes available you activate the service. My udev foo is a bit rusty but you can try something along the lines of... /etc/udev/rules.d/98-shk-local.rules SUBSYSTEM==input, ENV{ID_INPUT_KEYBOARD}==?*, ENV{.INPUT_CLASS}=kbd, TAG+=systemd, ENV{SYSTEMD_WANTS}+=shkd@%p.service /etc/systemd/system/shkd@.service [Unit] Description=Simple HotKey Daemon You really want a BindTo back to the .device unit here, so that the service is removed as soon as the device vanishes. [Service] ExecStart=/usr/local/bin/shkd %I Restart=always [Install] WantedBy=multi-user.target ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel Lennart -- Lennart Poettering, Red Hat ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Requiring hardware device and escaping device names
On Wed, 26.03.14 21:50, Kai Hendry (hen...@webconverger.com) wrote: Thanks Michael for answering, :) On 26 March 2014 18:59, Michael Biebl mbi...@gmail.com wrote: 2014-03-26 3:56 GMT+01:00 Kai Hendry hen...@webconverger.com: If your daemon is not functional if the hardware is not present, I'd probably start it via a udev rule and SYSTEMD_WANTS. Do you have an example for this please? I don't quite understand why I can't I just name the device in the service file. Why does it have to be so confusing. Still don't understand the need for escaping... is there a need? Well, on the command line we will actually escape automatically for you, i.e. systemctl status /dev/sda5 will magically turn into systemctl status dev-sda5.device. However, we make stricter requirements when writing unit files to avoid redundant syntaxes, and we should expect the admin to take a little more care... I think this is the right behaviour as it is OK to be a bit more sloppy (and hence user-friendly) for day-to-day command lines, and require more correctness when writing new files. Lennart -- Lennart Poettering, Red Hat ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Requiring hardware device and escaping device names
On Tue, Apr 1, 2014 at 6:45 AM, Kai Hendry hen...@webconverger.com wrote: On 31 March 2014 09:54, Kai Hendry hen...@webconverger.com wrote: Not sure what to try next? If I start it manually `sudo systemctl start shkd@-dev-input-event0.service`, it starts working again. Is http://www.freedesktop.org/software/systemd/man/systemd.service.html#TimeoutSec= the right way to proceed? Not sure. RestartSec=5 did the trick! Not sure why systemd gives up trying to restart a process, despite Restart=always http://ix.io/bog Using Bind on device name would be more logical. In this case systemd would stop service when deviced disappeared and restart when it appears again. This avoids permanent restart loop when device is not present. Still don't understand where [hendry@alarmpi ~]$ systemctl status shkd@sys-devices-platform-bcm2708_usb-usb1-1\x2d1-1\x2d1.2-1\x2d1.2.2-1\x2d1.2.2:1.0-input-input1.service shkd@sys-devices-platform-bcm2708_usb-usb1-1x2d1-1x2d1.2-1x2d1.2.2-1x2d1.2.2:1.0-input-input1.service - Simple HotKey Daemon Loaded: loaded (/etc/systemd/system/shkd@.service; disabled) Active: inactive (dead) Comes from. From systemctl status. As soon as unit is mentioned anywhere the stub for it is internally created by systemd (it resolves actual unit on-disk definition lazily). So your own command creates it :) ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Requiring hardware device and escaping device names
On 31 March 2014 09:54, Kai Hendry hen...@webconverger.com wrote: Not sure what to try next? If I start it manually `sudo systemctl start shkd@-dev-input-event0.service`, it starts working again. Is http://www.freedesktop.org/software/systemd/man/systemd.service.html#TimeoutSec= the right way to proceed? Not sure. RestartSec=5 did the trick! Not sure why systemd gives up trying to restart a process, despite Restart=always http://ix.io/bog Sidenote: Even though my /etc/udev/rules.d/98-shk-local.rules has ENV{SYSTEMD_WANTS}+=shkd@%N.service, how come shkd@sys-devices-platform-bcm2708_usb-usb1-1\x2d1-1\x2d1.2-1\x2d1.2.2-1\x2d1.2.2:1.0-input-input0.service shkd@sys-devices-platform-bcm2708_usb-usb1-1\x2d1-1\x2d1.2-1\x2d1.2.2-1\x2d1.2.2:1.0-input-input2.service show up?? These are sys devices (%p) not %N ($devnode). Still don't understand where [hendry@alarmpi ~]$ systemctl status shkd@sys-devices-platform-bcm2708_usb-usb1-1\x2d1-1\x2d1.2-1\x2d1.2.2-1\x2d1.2.2:1.0-input-input1.service shkd@sys-devices-platform-bcm2708_usb-usb1-1x2d1-1x2d1.2-1x2d1.2.2-1x2d1.2.2:1.0-input-input1.service - Simple HotKey Daemon Loaded: loaded (/etc/systemd/system/shkd@.service; disabled) Active: inactive (dead) Comes from. Kind regards, ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Requiring hardware device and escaping device names
On 26 March 2014 22:55, Jóhann B. Guðmundsson johan...@gmail.com wrote: SUBSYSTEM==input, ENV{ID_INPUT_KEYBOARD}==?*, ENV{.INPUT_CLASS}=kbd, TAG+=systemd, ENV{SYSTEMD_WANTS}+=shkd@%p.service Trying to teach myself how to fish here. How did you know it would match this particular device? $ udevadm monitor monitor will print the received events for: UDEV - the event which udev sends out after rule processing KERNEL - the kernel uevent KERNEL[290197.779159] remove /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2/1-1.2.2:1.0/input/input7/event0 (input) KERNEL[290197.788432] remove /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2/1-1.2.2:1.0/input/input7 (input) KERNEL[290197.791409] remove /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2/1-1.2.2:1.0/0003:13BA:0001.0008/hidraw/hidraw0 (hidr aw) KERNEL[290197.799059] remove /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2/1-1.2.2:1.0/0003:13BA:0001.0008 (hid) KERNEL[290197.799463] remove /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2/1-1.2.2:1.0 (usb) KERNEL[290197.799878] remove /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2 (usb) UDEV [290198.000420] remove /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2/1-1.2.2:1.0/input/input7/event0 (input) UDEV [290198.019272] remove /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2/1-1.2.2:1.0/0003:13BA:0001.0008/hidraw/hidraw0 (hidr aw) UDEV [290198.028247] remove /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2/1-1.2.2:1.0/input/input7 (input) UDEV [290198.033868] remove /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2/1-1.2.2:1.0/0003:13BA:0001.0008 (hid) UDEV [290198.051687] remove /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2/1-1.2.2:1.0 (usb) UDEV [290198.057794] remove /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2 (usb) KERNEL[290199.905920] add /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2 (usb) UDEV [290199.916744] add /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2 (usb) KERNEL[290199.918617] add /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2/1-1.2.2:1.0 (usb) KERNEL[290199.926306] add /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2/1-1.2.2:1.0/0003:13BA:0001.0009 (hid) KERNEL[290199.926697] add /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2/1-1.2.2:1.0/input/input8 (input) KERNEL[290199.934673] add /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2/1-1.2.2:1.0/input/input8/event0 (input) KERNEL[290199.936852] add /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2/1-1.2.2:1.0/0003:13BA:0001.0009/hidraw/hidraw0 (hidr aw) UDEV [290199.979780] add /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2/1-1.2.2:1.0 (usb) UDEV [290200.026897] add /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2/1-1.2.2:1.0/0003:13BA:0001.0009 (hid) UDEV [290200.046996] add /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2/1-1.2.2:1.0/0003:13BA:0001.0009/hidraw/hidraw0 (hidr aw) UDEV [290200.059797] add /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2/1-1.2.2:1.0/input/input8 (input) UDEV [290200.121850] add /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2/1-1.2.2:1.0/input/input8/event0 (input) /etc/systemd/system/shkd@.service [Unit] Description=Simple HotKey Daemon [Service] ExecStart=/usr/local/bin/shkd %I Restart=always [Install] WantedBy=multi-user.target So IIUC, just have the udev rule there will start the systemd service. No need to enable anything? Anyway, it doesn't seem to work. [hendry@alarmpi ~]$ systemctl | grep shk shkd@-devices-platform-bcm2708_usb-usb1-1-1-1-1.2-1-1.2.2-1-1.2.2:1.0-input-input0-event0.service loaded failed failed Simple HotKey Daemon shkd@-devices-platform-bcm2708_usb-usb1-1-1-1-1.2-1-1.2.2-1-1.2.2:1.0-input-input0.service loaded failed failed Simple HotKey Daemon system-shkd.slice loaded active active system-shkd.slice [hendry@alarmpi ~]$ sudo systemctl status shkd@-devices-platform-bcm2708_usb-usb1-1-1-1-1.2-1-1.2.2-1-1.2.2:1.0-input-input0-event0.service shkd@-devices-platform-bcm2708_usb-usb1-1-1-1-1.2-1-1.2.2-1-1.2.2:1.0-input-input0-event0.service - Simple HotKey Daemon Loaded: loaded (/etc/systemd/system/shkd@.service; disabled) Active: failed (Result: start-limit) since Thu 1970-01-01 07:30:16 SGT; 44 years 2 months ago Process: 200 ExecStart=/usr/local/bin/shkd %I (code=exited, status=1/FAILURE) Main PID: 200 (code=exited, status=1/FAILURE) Jan 01 07:30:16 alarmpi systemd[1]: Unit shkd@-devices-platform-bcm2708_usb-usb1-1-1-1-1.2-1-1.2.2-1-1.2.2:1.0-input-input0-ev... state. Jan 01 07:30:16 alarmpi systemd[1]: shkd@-devices-platform-bcm2708_usb-usb1-1-1-1-1.2-1-1.2.2-1-1.2.2:1.0-input-input0-event0estart. Jan 01 07:30:16 alarmpi systemd[1]: Stopping Simple HotKey Daemon... Jan 01 07:30:16 alarmpi systemd[1]: Starting Simple HotKey Daemon... Jan 01 07:30:16 alarmpi systemd[1]:
Re: [systemd-devel] Requiring hardware device and escaping device names
В Sun, 30 Mar 2014 23:48:11 +0800 Kai Hendry hen...@webconverger.com пишет: On 26 March 2014 22:55, Jóhann B. Guðmundsson johan...@gmail.com wrote: SUBSYSTEM==input, ENV{ID_INPUT_KEYBOARD}==?*, ENV{.INPUT_CLASS}=kbd, TAG+=systemd, ENV{SYSTEMD_WANTS}+=shkd@%p.service ... Trying to teach myself how to fish here. How did you know it would match this particular device? $ udevadm monitor udevadm monitor --env would be more useful, it also shows device attributes after event is processed. ... Anyway, it doesn't seem to work. [hendry@alarmpi ~]$ systemctl | grep shk shkd@-devices-platform-bcm2708_usb-usb1-1-1-1-1.2-1-1.2.2-1-1.2.2:1.0-input-input0-event0.service loaded failed failed Simple HotKey Daemon That's right. You really want %N ($devnode), not %p in the rule. %p refers to path in /sys, while your daemon apparently needs real device path in /dev. To filter those paths that generate device nodes you could check for DEVNAME or NAME not being empty. If you need more specific match, you need to check attributes for your device. SUBSYSTEM==input, ENV{ID_INPUT_KEYBOARD}==?*, ENV{DEVNAME}==?*, \ TAG+=systemd, ENV{SYSTEMD_WANTS}+=shkd@%N.service ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Requiring hardware device and escaping device names
On 31 March 2014 01:00, Andrey Borzenkov arvidj...@gmail.com wrote: udevadm monitor --env would be more useful, it also shows device attributes after event is processed. Thank you Andrey! With %N and a reboot, the keyboard is working. However for interest sake, I un-plugged the USB device and re-inserted it and it doesn't work. Picture of it: http://up.dabase.com/2014-03-31/image.webp Here is the `udevadm monitor --env` log: http://sprunge.us/MFPQ I think shkd@-dev-input-event0.service start request repeated too quickly, refusing to start. is the issue. [hendry@alarmpi ~]$ systemctl --full | grep shk shkd@-dev-input-event0.service loaded failed failed Simple HotKey Daemon shkd@sys-devices-platform-bcm2708_usb-usb1-1\x2d1-1\x2d1.2-1\x2d1.2.2-1\x2d1.2.2:1.0-input-input0.service loaded failed failed Simple HotKey Daemon shkd@sys-devices-platform-bcm2708_usb-usb1-1\x2d1-1\x2d1.2-1\x2d1.2.2-1\x2d1.2.2:1.0-input-input2.service loaded failed failed Simple HotKey Daemon system-shkd.slice loaded active active system-shkd.slice [hendry@alarmpi ~]$ systemctl status shkd@-dev-input-event0.service shkd@-dev-input-event0.service - Simple HotKey Daemon Loaded: loaded (/etc/systemd/system/shkd@.service; disabled) Active: failed (Result: start-limit) since Mon 2014-03-31 09:30:21 SGT; 5min ago Process: 443 ExecStart=/usr/local/bin/shkd %I (code=exited, status=1/FAILURE) Main PID: 443 (code=exited, status=1/FAILURE) Mar 31 09:30:21 alarmpi systemd[1]: Unit shkd@-dev-input-event0.service entered failed state. Mar 31 09:30:21 alarmpi systemd[1]: shkd@-dev-input-event0.service holdoff time over, scheduling restart. Mar 31 09:30:21 alarmpi systemd[1]: Stopping Simple HotKey Daemon... Mar 31 09:30:21 alarmpi systemd[1]: Starting Simple HotKey Daemon... Mar 31 09:30:21 alarmpi systemd[1]: shkd@-dev-input-event0.service start request repeated too quickly, refusing to start. Mar 31 09:30:21 alarmpi systemd[1]: Failed to start Simple HotKey Daemon. Mar 31 09:30:21 alarmpi systemd[1]: Unit shkd@-dev-input-event0.service entered failed state. Mar 31 09:30:25 alarmpi systemd[1]: Starting Simple HotKey Daemon... Mar 31 09:30:25 alarmpi systemd[1]: shkd@-dev-input-event0.service start request repeated too quickly, refusing to start. Mar 31 09:30:25 alarmpi systemd[1]: Failed to start Simple HotKey Daemon. Not sure what to try next? If I start it manually `sudo systemctl start shkd@-dev-input-event0.service`, it starts working again. Is http://www.freedesktop.org/software/systemd/man/systemd.service.html#TimeoutSec= the right way to proceed? Not sure. Sidenote: Even though my /etc/udev/rules.d/98-shk-local.rules has ENV{SYSTEMD_WANTS}+=shkd@%N.service, how come shkd@sys-devices-platform-bcm2708_usb-usb1-1\x2d1-1\x2d1.2-1\x2d1.2.2-1\x2d1.2.2:1.0-input-input0.service shkd@sys-devices-platform-bcm2708_usb-usb1-1\x2d1-1\x2d1.2-1\x2d1.2.2-1\x2d1.2.2:1.0-input-input2.service show up?? These are sys devices (%p) not %N ($devnode). Hoping you can guide me further. :) Kind regards, ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Requiring hardware device and escaping device names
2014-03-26 3:56 GMT+01:00 Kai Hendry hen...@webconverger.com: On 25 March 2014 18:01, Kai Hendry hen...@webconverger.com wrote: Requires=dev-input-by\x2did-usb\x2d13ba_0001\x2devent\x2dkbd.device On #systemd IRC I was recommended After=, and I think it's working as it should! After=dev-input-by\x2did-usb\x2d13ba_0001\x2devent\x2dkbd.device Is Requires= incorrect? Is my escaping correct? Do I need to actually escape in the first place? Hm, I'm not sure if After is the right solution. What if your keyboard is not attached during boot? If your daemon is not functional if the hardware is not present, I'd probably start it via a udev rule and SYSTEMD_WANTS. In addition, if you want your service is stopped whenever the hardware goes away, you can use BindTo in the service file -- Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth? ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Requiring hardware device and escaping device names
Thanks Michael for answering, :) On 26 March 2014 18:59, Michael Biebl mbi...@gmail.com wrote: 2014-03-26 3:56 GMT+01:00 Kai Hendry hen...@webconverger.com: If your daemon is not functional if the hardware is not present, I'd probably start it via a udev rule and SYSTEMD_WANTS. Do you have an example for this please? I don't quite understand why I can't I just name the device in the service file. Why does it have to be so confusing. Still don't understand the need for escaping... is there a need? Thank you, ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Requiring hardware device and escaping device names
On 03/26/2014 01:50 PM, Kai Hendry wrote: Thanks Michael for answering, :) On 26 March 2014 18:59, Michael Biebl mbi...@gmail.com wrote: 2014-03-26 3:56 GMT+01:00 Kai Hendry hen...@webconverger.com: If your daemon is not functional if the hardware is not present, I'd probably start it via a udev rule and SYSTEMD_WANTS. Do you have an example for this please? I don't quite understand why I can't I just name the device in the service file. Why does it have to be so confusing. Still don't understand the need for escaping... is there a need? The reason is when your hardware becomes available you activate the service. My udev foo is a bit rusty but you can try something along the lines of... /etc/udev/rules.d/98-shk-local.rules SUBSYSTEM==input, ENV{ID_INPUT_KEYBOARD}==?*, ENV{.INPUT_CLASS}=kbd, TAG+=systemd, ENV{SYSTEMD_WANTS}+=shkd@%p.service /etc/systemd/system/shkd@.service [Unit] Description=Simple HotKey Daemon [Service] ExecStart=/usr/local/bin/shkd %I Restart=always [Install] WantedBy=multi-user.target ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Requiring hardware device and escaping device names
On 2014-03-26 14:50, Kai Hendry wrote: Thanks Michael for answering, :) On 26 March 2014 18:59, Michael Biebl mbi...@gmail.com wrote: 2014-03-26 3:56 GMT+01:00 Kai Hendry hen...@webconverger.com: If your daemon is not functional if the hardware is not present, I'd probably start it via a udev rule and SYSTEMD_WANTS. Do you have an example for this please? I don't quite understand why I can't I just name the device in the service file. Why does it have to be so confusing. Still don't understand the need for escaping... is there a need? While Jóhann has answered the technical part of your question, I'd like to address the quoting part: in the various configuration locations you were talking about earlier, quoting of filenames is required as these config directives can take a wide range of arguments that can reference many other things beside devices. Since those units are all defined in files, whose names are the unit name, all those names have to be valid file names. So a unit can also Requires=foo.service, which will be defined in a file called foo.service. The specifics are described in http://www.freedesktop.org/software/systemd/man/systemd.unit.html: Some unit names reflect paths existing in the file system namespace. Example: a device unit dev-sda.device refers to a device with the device node /dev/sda in the file system namespace. If this applies, a special way to escape the path name is used, so that the result is usable as part of a filename. Basically, given a path, / is replaced by -, and all unprintable characters and the - are replaced by C-style \x20 escapes. The root directory / is encoded as single dash, while otherwise the initial and ending / is removed from all paths during transformation. This escaping is reversible. Regards, David ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Requiring hardware device and escaping device names
On 25 March 2014 18:01, Kai Hendry hen...@webconverger.com wrote: Requires=dev-input-by\x2did-usb\x2d13ba_0001\x2devent\x2dkbd.device On #systemd IRC I was recommended After=, and I think it's working as it should! After=dev-input-by\x2did-usb\x2d13ba_0001\x2devent\x2dkbd.device Is Requires= incorrect? Is my escaping correct? Do I need to actually escape in the first place? Btw I quickly put together a escaping and un-escaping tool here: http://systemd.dabase.com/ I'd really appreciate a review. I still don't quite understand why systemd can't take /dev/input/by-id/usb-13ba_0001-event-kbd and realise it's a device. I.e. the need for it to be escaped. Kind regards, ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel