[systemd-devel] killmode

Mike Gilbert floppym at gentoo.org
Fri May 20 17:37:57 UTC 2022


On Fri, May 20, 2022 at 1:34 PM Mike Gilbert <floppym at gentoo.org> wrote:
>
> On Fri, May 20, 2022 at 12:54 PM Pascal <patatetom at gmail.com> wrote:
> >
> > not really in the sense that qemu-nbd launches and immediately gives the hand back to the script that called it.
> > the script ends positively and qemu-nbd is killed by systemd because it is considered to be garbage left behind by the script.
> > this is not quite the case of a timeout that systemd terminates, but the result is the same.
> > in this case, qemu-nbd looks more like a daemon.
> >
> > I was wondering if there was a way to propagate the killmode through a udev rule that starts a script (like a service)... but it seems from the documentation that the answer is no :-(
> >
> > """In order to activate long-running processes from udev rules, provide a service unit and pull it in from a udev device using the SYSTEMD_WANTS device property. See systemd.device(5) for details."""
> > I would appreciate (and maybe I won't be the only one) a concrete example based, for example,  on my problem ;-)
> >
> > let's just say that my rule is :
> >
> > KERNEL=="sdb", RUN+="/usr/local/sbin/myscript"
> >
> > and my script is :
> >
> > #!/usr/bin/bash
> > qemu-nbd -r -s -f raw -c /dev/nbd0 /dev/sdb
>
> The most direct translation would be something like this:
>
> qemu-nbd0-sdb.service:
> [Service]
> ExecStart=qemu-nbd -r -s -f raw -c /dev/nbd0 /dev/sdb
>
> udev rule:
> KERNEL=="sdb", ENV{SYSTEMD_WANTS}+="qemu-nbd0-sdb.service"

Oh, you'll want to add Type=forking to the .service file if it always
forks a child and exits.


More information about the systemd-devel mailing list