[systemd-devel] Service reactivation with device plugging
Mirco Tischler
mt-ml at gmx.de
Tue Jul 3 17:34:33 PDT 2012
2012/7/4 Kok, Auke-jan H <auke-jan.h.kok at intel.com>:
> On Tue, Jul 3, 2012 at 4:49 PM, Rob Spanton <rspanton at zepler.net> wrote:
>> Hi,
>>
>> I wrote:
>>> I was recently working on an embedded system that had a daemon
>>> [ ...which] needed to be run when both [serial] devices were plugged
>>> in. If any of the devices was unplugged, the daemon would exit, and
>>> would need to be restarted the next time both devices were plugged in.
>>
>> Auke wrote:
>>> why not write a middle-man layer that uses socket activation?
>>
>> My understanding of socket activation is that it is for starting a
>> service when something attempts to connect to a socket. I don't
>> understand how this relates to my situation with two serial devices.
>>
>>> alternatively, you could use inotify and immediately start your
>>> daemon.
>>
>> Presumably you mean by writing a second daemon that uses inotify? Yes,
>> I can see that this would solve my problem, however I was wondering
>> whether there was a simpler way of doing it just using systemd.
>
> I'm more throwing ideas out there at this point, I don't know the
> whole situation.
>
> First, things can be a lot easier if components use proper methods.
> For device nodes, udev rules should be the way to go.
>
> You can have udev do things for you if the devices appear, so that
> should be one line of approach: have udev start something for you.
>
> You could make a program that just exits if only one device is
> available, and runs if two are available. Once udev sees the second
> device, things will just work.
>
> Auke
Seconded. For clues on how to let udev start things for you see the
systemd.device man page A unit like this should work with udev
activation:
[Unit]
Description=...
BindTo=dev-serial-a.device dev-serial-b.device
After=dev-serial-a.device dev-serial-b.device
[Service]
ExecStart=/usr/bin/my-magic-service
Type=notify
Mirco
More information about the systemd-devel
mailing list