[systemd-devel] Requiring hardware device and escaping device names

Lennart Poettering lennart at poettering.net
Wed Apr 23 14:18:24 PDT 2014


On Wed, 26.03.14 14:55, Jóhann B. Guðmundsson (johannbg at 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 <mbiebl at gmail.com> wrote:
> >>2014-03-26 3:56 GMT+01:00 Kai Hendry <hendry at 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 at .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 at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list