[systemd-devel] systemctl and detach in udev RUN

Lennart Poettering lennart at poettering.net
Mon Oct 10 13:46:40 PDT 2011


On Thu, 06.10.11 13:14, Albert Strasheim (fullung at gmail.com) wrote:

> 
> Hello
> 
> On Thu, Oct 6, 2011 at 1:05 PM, Kay Sievers <kay.sievers at vrfy.org> wrote:
> > On Thu, Oct 6, 2011 at 11:29, Albert Strasheim <fullung at gmail.com> wrote:
> >> On Wed, Oct 5, 2011 at 4:10 PM, Albert Strasheim <fullung at gmail.com> wrote:
> >>> Hello all
> >>> I have the following udev rule in a machine with a bunch of disks:
> >>> SUBSYSTEM=="block", KERNEL=="sd*", TAG+="systemd", ACTION=="add",
> >>> RUN+="/bin/systemctl restart blockinit@%k.service"
> >> To answer myself: systemctl has a --no-block option that seems like
> >> the right thing to do here.
> > It doesn't sound right, to call systemd from udev context. You might
> > want to try if:
> >  SYSTEMD_WANTS= (man systemd.device)
> > works for you.
> 
> I've tried SYSTEMD_WANTS in the past, but it doesn't quite do what I want.
> 
> Usually when a device is re-added to the system, I want to restart the
> associated service.

Place a BindTo= in the service so that it gets shut down when the device
is removed.

> I'm also not quite sure how SYSTEMD_WANTS deals with failed services:
> does it restart them if the device added again?

Yes. We never inhibit starting of services when they failed before if
the starting is triggered by the user or pulled in as dependency.

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list