<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <br>
    <br>
    <div class="moz-cite-prefix">On 15/09/2017 07:27, Luiz Angelo Daros
      de Luca wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAJq09z53CMsL_2G+YG_fgB=332+Ui4K55_2XxkMW=Y+UupQWpA@mail.gmail.com"><span>Thanks Jérémy,</span>
      <div><br>
      </div>
      <div>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.</div>
      <div>
        <div class="gmail_quote">
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex"
            id="gmail_block_quote0">
            <div text="#000000" bgcolor="#FFFFFF">
              <blockquote type="cite"> </blockquote>
            </div>
            <div text="#000000" bgcolor="#FFFFFF"> you could create a
              template (<a
                class="m_-987163146845524182moz-txt-link-abbreviated"
                href="mailto:xendomains@.service" target="_blank"
                moz-do-not-send="true">xendomains@.service</a>) and use
              drop-ins to do per-instance overrides
              (/etc/systemd/system/xendomains@vm1.service.d/append.conf)
              that would allow you to individualize each domain while
              keeping the common parts<br>
              <br>
              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...</div>
          </blockquote>
        </div>
      </div>
      <div><br>
      </div>
      <div>I would use a template like <a class="moz-txt-link-abbreviated" href="mailto:xendomains@.service">xendomains@.service</a> 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?</div>
    </blockquote>
    <br>
    <blockquote type="cite"
cite="mid:CAJq09z53CMsL_2G+YG_fgB=332+Ui4K55_2XxkMW=Y+UupQWpA@mail.gmail.com">
      <div><br>
      </div>
      <div>Also, should I use a service patch (like append.conf you
        mentioned) or simply directly create
        /run/.../xendomains@vm1.service?<br>
      </div>
      <div><br>
      </div>
    </blockquote>
    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...<br>
    <blockquote type="cite"
cite="mid:CAJq09z53CMsL_2G+YG_fgB=332+Ui4K55_2XxkMW=Y+UupQWpA@mail.gmail.com">
      <div>It would be trivial to define a template <a class="moz-txt-link-abbreviated" href="mailto:xendomains@.service">xendomains@.service</a>
        and start services like "systemctl start
        <a class="moz-txt-link-abbreviated" href="mailto:xendomains@vm1.service">xendomains@vm1.service</a>", 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=.</div>
    </blockquote>
    A generator is probably the way to go... generators can create ANY
    systemd configuration files, including templates, drop-ins and
    .wants directory<br>
    <br>
    You probably already found that, but in case you didn't, you should
    read the DESCRIPTION section of <a class="moz-txt-link-freetext" href="man:systemd.unit">man:systemd.unit</a> It describes all
    the ways you can add files to configure units<br>
    <br>
    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...<br>
    <blockquote type="cite"
cite="mid:CAJq09z53CMsL_2G+YG_fgB=332+Ui4K55_2XxkMW=Y+UupQWpA@mail.gmail.com">
      <div><br>
      </div>
      <div>Instances seems to be created only when asked directly
        (systemctl start <a class="moz-txt-link-abbreviated" href="mailto:xendomains@vm1.service">xendomains@vm1.service</a>), which might be
        triggered by something like udev event. Is there anything like
        ExecListStartInstances=, ExecListRunningInstances=?</div>
    </blockquote>
    see my answer above. There is no such thing, but generators can do
    the equivalent by creating a .wants link <br>
    <br>
    (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)<br>
    <blockquote type="cite"
cite="mid:CAJq09z53CMsL_2G+YG_fgB=332+Ui4K55_2XxkMW=Y+UupQWpA@mail.gmail.com">
      <div>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.</div>
    </blockquote>
    what would be your use-case ? <br>
    status is not "an event" nothing real happens on status<br>
    start/stop can propagate stuff based on their parameters, but the
    services themselves are not meant to be dynamic...<br>
    <br>
    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<br>
    <br>
    <blockquote type="cite"
cite="mid:CAJq09z53CMsL_2G+YG_fgB=332+Ui4K55_2XxkMW=Y+UupQWpA@mail.gmail.com">
      <div><br>
      </div>
      <div>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 <a class="moz-txt-link-abbreviated" href="mailto:xendomains@.service">xendomains@.service</a> 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 <a class="moz-txt-link-abbreviated" href="mailto:xendomains@vm.service">xendomains@vm.service</a>,
        in order to avoid to start a disabled-after-boot vm. However,
        this does not look like an elegant solution.</div>
    </blockquote>
    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<br>
    <br>
    * use templates to define how to start vms (common parts in the
    template, particularities in the instances)<br>
    * 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)<br>
    <br>
    <br>
    Hope this helps<br>
    <br>
    Jérémy<br>
    <br>
    <blockquote type="cite"
cite="mid:CAJq09z53CMsL_2G+YG_fgB=332+Ui4K55_2XxkMW=Y+UupQWpA@mail.gmail.com">
      <div><br>
      </div>
      <div>Regards,</div>
      <div>
        <div class="gmail_quote">
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex"
            id="gmail_block_quote0">
          </blockquote>
        </div>
      </div>
      <div dir="ltr">-- <br>
      </div>
      <div class="gmail_signature" data-smartmail="gmail_signature">
        <div dir="ltr">
          <p dir="ltr">Luiz Angelo Daros de Luca<br>
            <a href="mailto:luizluca@gmail.com" moz-do-not-send="true">luizluca@gmail.com</a></p>
        </div>
      </div>
    </blockquote>
    <br>
    <div class="moz-signature">-- <br>
      <div style="border-bottom: 1px solid #ccd4d7; margin:0 10px 10px
        0; width:600px"> </div>
      <div>
        <table style="; padding: 15px 0 0 0" border="0">
          <tbody>
            <tr>
              <td style="font-size:11px; color:#56707d; text-align:
                center; "> <a href="http://www.smile.fr/"><img
                    src="http://ftp.smile.fr/client/Communication/signature/img/Logo.png"
                    alt="Logo" width="129" height="47"></a><br>
                <br>
                <font face="century gothic, arial, sans-serif">20 rue
                  des Jardins<br>
                  92600 Asnières-sur-Seine<br>
                  <a href="http://www.smile.fr/" style="font-size:14px;
                    color:#ec6608 ; text-decoration:none;">www.smile.fr</a></font>
              </td>
              <td style="padding-left:35px; font-size:12px;
                color:#56707d">
                <div style="color:#153358; font-size:12px;"><font
                    face="century gothic, arial, sans-serif"><b>Jérémy
                      ROSEN</b></font></div>
                <div style="color:#117eb4; font-size:12px;"><font
                    face="century gothic, arial, sans-serif">Architecte
                    technique<br>
                  </font></div>
                <div style="color:#56707d; font-size:12px;"><font
                    face="century gothic, arial, sans-serif">Email : <a
                      href="mailto:jeremy.rosen@smile.fr"
                      style="color:#56707d; font-size:12px;
                      text-decoration:none;">jeremy.rosen@smile.fr</a> <br>
                    Tel : +33141402967 </font></div>
                <br>
                <div> <span><a
                      href="https://www.facebook.com/smileopensource"><img
src="http://ftp.smile.fr/client/Communication/signature/img/Facebook.png"
                        alt="Facebook" width="25" height="24"></a></span>
                  <span><a
                      href="http://fr.slideshare.net/SmileOpenSource/presentations"><img
src="http://ftp.smile.fr/client/Communication/signature/img/Slideshare.png"
                        alt="Google%2B" width="25" height="24"></a></span>
                  <span><a href="https://www.linkedin.com/company/smile"><img
src="http://ftp.smile.fr/client/Communication/signature/img/LinkedIn.png"
                        alt="LinkedIn" width="25" height="24"></a></span>
                  <span><a href="https://twitter.com/GroupeSmile"><img
                        src="http://ftp.smile.fr/client/Communication/signature/img/Twitter.png"
                        alt="Twitter" width="25" height="24"></a></span>
                </div>
              </td>
            </tr>
          </tbody>
        </table>
        <div style="border-bottom: 1px solid #ccd4d7; margin:0 10px 0 0;
          width:600px"> </div>
        <br>
        <div> <a
href="http://www.smile.fr/Offres-services/Offres/Ingenierie?utm_source=signature&utm_medium=email&utm_campaign=signature"><img
src="http://signature.smile.eu/assets/img/OW_devient_Smile_ECS.png"
              alt="bandeaux_mail" border="0"></a></div>
        <br>
        <div style="color:#a3acb5; font-size:10px;"> <img
            src="http://ftp.smile.fr/client/Communication/signature/img/eco.png"
            alt="eco" width="13" height="11"> <font face="century
            gothic, arial, sans-serif"> Pour la planète, n'imprimez ce
            mail que si c'est nécessaire </font> </div>
      </div>
    </div>
  </body>
</html>