[systemd-devel] How to properly write an "umbrella" unit
Colin Guthrie
colin at mageia.org
Tue Jul 21 05:40:31 PDT 2015
Marc Haber wrote on 21/07/15 12:43:
> 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
>
> [Install]
> WantedBy=multi-user.target
>
>
> nifty-v4.service:
> [Unit]
> Description=nifty Server for IPv4 (niftyd4.conf)
> After=network.target
> PartOf=nifty.target
>
> [Service]
> ExecStart=/usr/sbin/niftyd -f -4 -q -cf /etc/nifty/niftyd4.conf
>
> [Install]
> WantedBy=nifty.target
>
>
>
> nifty-v6.service:
> [Unit]
> Description=nifty Server for IPv6
> After=network.target
> PartOf=nifty.target
>
> [Service]
> ExecStart=/usr/sbin/niftyd -f -6 -q -cf /etc/nifty/niftyd6.conf
>
> [Install]
> WantedBy=nifty.target
>
>
> 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.
In this case, I'd perhaps recommend NOT including [Install] sections fir
your two .service files and instead make your "make install" action
write symlinks into /usr/lib/systemd/system/nifty.target.wants.d/ thus
the user could never disable the individual components of your daemon
themselves and thus not need to rely on distro scripts to create them at
install time.
Your package install script would still have to enable (or preset) the
nifty.target however.
This might or might not be desirable overall (in the example above, I
can imagine someone still wanting to disable only the IPv6 component for
example!).
Col
--
Colin Guthrie
colin(at)mageia.org
http://colin.guthr.ie/
Day Job:
Tribalogic Limited http://www.tribalogic.net/
Open Source:
Mageia Contributor http://www.mageia.org/
PulseAudio Hacker http://www.pulseaudio.org/
Trac Hacker http://trac.edgewall.org/
More information about the systemd-devel
mailing list