[systemd-devel] How to specify dynamic services/requirements
Jérémy Rosen
jeremy.rosen at smile.fr
Fri Sep 15 08:02:32 UTC 2017
On 15/09/2017 07:27, Luiz Angelo Daros de Luca wrote:
> Thanks Jérémy,
>
> That was what I needed. I was afraid to be headed to the wrong way.
> Now that I know what to do, I need to know where and when.
>
> you could create a template (xendomains at .service
> <mailto:xendomains at .service>) and use drop-ins to do per-instance
> overrides
> (/etc/systemd/system/xendomains at vm1.service.d/append.conf) that
> would allow you to individualize each domain while keeping the
> common parts
>
> I would find a way to prevent a domain with no corresponding to
> start (maybe by not defining a mandatory key in the template) to
> make sure no rogue domains are created...
>
>
> I would use a template like xendomains at .service in order to specify
> common stuff. However, the config of which vm are enabled (autostart)
> is only available at boot time. Is a systemd generator the way to go?
> Is is there another way to define it?
>
> Also, should I use a service patch (like append.conf you mentioned) or
> simply directly create /run/.../xendomains at vm1.service?
>
both method work... the first one allow to add stuff to the common
template, the second to override more easily in the case of a VM that is
totally different from the others...
> It would be trivial to define a template xendomains at .service and start
> services like "systemctl start xendomains at vm1.service", that would
> read /etc/xen/vm/vm1 and launch it. I just don't know how I could
> define dynamic dependency for that instance depending on the content
> of /etc/xen/vm/vm1. Execstartpre can check requirements and prevent a
> service to run but not wait for a resource to be available. It would
> be something like ExecRequires=.
A generator is probably the way to go... generators can create ANY
systemd configuration files, including templates, drop-ins and .wants
directory
You probably already found that, but in case you didn't, you should read
the DESCRIPTION section of man:systemd.unit It describes all the ways
you can add files to configure units
In particular, if you want a service started at boot time, you need to
create a default.target.wants/ directory and add a symbolic link to the
unit to start in there. Populating such a directory at boot time with a
generator might be the best approch for you...
>
> Instances seems to be created only when asked directly (systemctl
> start xendomains at vm1.service), which might be triggered by something
> like udev event. Is there anything like
> ExecListStartInstances=, ExecListRunningInstances=?
see my answer above. There is no such thing, but generators can do the
equivalent by creating a .wants link
(as a side note, I don't know if you could do a "systemctl enable
--runtime" from a generator. maybe someone else here would know)
> Generators can create something like that but they are triggered only
> at boot and daemon-reload. It would be interesting to somehow run
> "something like generators" when start/stop/status is called.
what would be your use-case ?
status is not "an event" nothing real happens on status
start/stop can propagate stuff based on their parameters, but the
services themselves are not meant to be dynamic...
That being said, it might be possible to dinamically add dependencies to
a unit via dbus and/or systemctl set-property, but I have never tried
it, so you'll need to try and see
>
> From what I know about systemd, I'm thinking of something like a
> generator that will create services for all autostart and saved vm.
> The current script-based xendomains.service will run after
> all xendomains at .service instances. This way, a new enabled-after-boot
> vm would be started with "systemctl restart xendomains". I could use
> the existence of /etc/xen/auto/vm or /var/lib/xen/save/vm as
> requirement for xendomains at vm.service, in order to avoid to start a
> disabled-after-boot vm. However, this does not look like an elegant
> solution.
Your requirements seems very complex (and, I have to admit, a bit hard
to understand through e-mail) but I think that with a good understanding
of templates and generators it can be solved elegantly
* use templates to define how to start vms (common parts in the
template, particularities in the instances)
* add all boot-time depedencies via .wants directory via a generator
(maybe usint systemctl enable if it can be run at generator-time, but
i'm not sure it's possible)
Hope this helps
Jérémy
>
> Regards,
>
> --
>
> Luiz Angelo Daros de Luca
> luizluca at gmail.com <mailto:luizluca at gmail.com>
>
--
Logo <http://www.smile.fr/>
20 rue des Jardins
92600 Asnières-sur-Seine
www.smile.fr <http://www.smile.fr/>
*Jérémy ROSEN*
Architecte technique
Email : jeremy.rosen at smile.fr <mailto:jeremy.rosen at smile.fr>
Tel : +33141402967
Facebook <https://www.facebook.com/smileopensource> Google%2B
<http://fr.slideshare.net/SmileOpenSource/presentations> LinkedIn
<https://www.linkedin.com/company/smile> Twitter
<https://twitter.com/GroupeSmile>
bandeaux_mail
<http://www.smile.fr/Offres-services/Offres/Ingenierie?utm_source=signature&utm_medium=email&utm_campaign=signature>
eco Pour la planète, n'imprimez ce mail que si c'est nécessaire
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20170915/58a8eda0/attachment.html>
More information about the systemd-devel
mailing list