[systemd-devel] How to properly write an "umbrella" unit
Lennart Poettering
lennart at poettering.net
Wed Jul 22 10:15:32 PDT 2015
On Tue, 21.07.15 13:43, Marc Haber (mh+systemd-devel at zugschlus.de) wrote:
> Hi,
>
> I am trying to systemd'ize a daemon which is useful to be run in two
> instances. It is usually the case that both instances need to be
> started and stopped simultaneously, and the local admin would want a
> _single_ command to start and stop both instances. Therefore, an
> "umbrella" is needed.
>
> As a beginner, I have written:
>
> nifty.target:
> [Unit]
> Description=nifty Server (all protocols)
> After=network.target
Unrelated to the actual topic of this thread: this line above usually
doesn't do what people assume it does: It does not start the daemon
after the network is up -- which is what most folks might think --,
that's what network-online.target is for. Also, most daemons actually
don't need the network to be up, and it is bad style to make daemons
wait for external events such as DHCP events anyway. Hence, don't use
this. The primary effect of ordering something after network.target is
actually at shut down, since it ensures that the service is stopped
before the network is turned off.) It is usually a good to remove
such lines, unless you really really know you need it. In this case
the target should definitely not list this, if at all the services
should, but probably not even they.
> This works as designed. Unfortunately, my Distribution's build tools
> don't handle package-provided targets too well, and I feel that using
> a target here is kind of wrong anyway.
Going for a target for this sounds like the right choice, and if your
distro cannot support that nicely, it really should be improved to
support it.
> Can I write my nifty.target as a service? I have seen in this case
> nifty.service files with Exec=/bin/true to basically create a no-op
> service, but that's ugly.
That's a hack. A target is for grouping things, they basically are
services without processes attached to them. You really should use
targets for this, and not misuse services.
> If I move my service to a nifty at .service, how would I start two
> instances from a single shell command?
You can also group instances with a target unit nicely. But the way to
group things is via target units, nothing else.
> How would one handle this situation in the clear, recommended way?
The way you already did it!
Lennart
--
Lennart Poettering, Red Hat
More information about the systemd-devel
mailing list