[systemd-devel] Service reactivation with device plugging
Lennart Poettering
lennart at poettering.net
Mon Jul 9 15:15:26 PDT 2012
On Wed, 04.07.12 00:10, Rob Spanton (rspanton at zepler.net) wrote:
> Hi,
>
> I was recently working on an embedded system that had a daemon that
> depended on the presence of two USB serial devices. The daemon needed
> to be run when both 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.
>
> I created a service file pretty-much like the one at the end of this
> email. This kind-of did what I wanted for a short while. However, if
> the daemon was running, and then I unplugged the serial devices, systemd
> seemed to attempt to continuously restart the daemon despite the serial
> devices not being present. Furthermore, it seemed to give up doing this
> after some period of time (not sure exactly how long, but somewhere
> around minute or two). Once it had given up restarting the daemon, the
> daemon was not restarted when I plugged the devices back in again.
>
> In the end, due to looming deadlines, I added a cron job that just ran
> `systemctl start mydaemon.service` every minute to ensure that systemd
> didn't give up on reactivating the service.
>
> Am I missing something here? Is this a valid application of systemd?
Yes it is, absolutely.
Requires= is used for deps that only need to be fulfilled at startup
time of a service. BindTo= is for deps that need to be fulfilled all the
time. So for your case you should be able to simply replace Requires= by
BindTo= and that should be it.
> [Unit]
> Description=...
> Requires=dev-serial-a.device
> Requires=dev-serial-b.device
^^^^^^^^
Use BindTo= here
Lennart
--
Lennart Poettering - Red Hat, Inc.
More information about the systemd-devel
mailing list