systemd-formula icon indicating copy to clipboard operation
systemd-formula copied to clipboard

[BUG] Formula try do start/stop multiinstance service - it won't work

Open unix196 opened this issue 4 years ago • 1 comments

https://www.stevenrombauts.be/2019/01/run-multiple-instances-of-the-same-systemd-unit/ I needed to start multiple instances of a single unit automatically with systemd, write config like this:

systemctl cat browser.target
[Install]
WantedBy=multi-user.target

[Unit]
After=network.target
Description=Chromium target
[email protected]
[email protected]
[email protected]

systemctl cat [email protected]
[Service]
ExecStart=some_command
Group=chromium
...
Type=simple

[Unit]
After=network.target
Description=Browser runner %i
PartOf=browser-runner.target

Multiinstance unit service didn't support enable/disable or start/stop (it's like a template). Start/stop or enable/disable I can only with target or explicitly given instances:

systemctl  status [email protected]
systemctl  is-enabled browser-runner.target

systemctl  status [email protected]
Failed to get properties: Unit name [email protected] is missing the instance name.

systemctl  status [email protected][email protected] - Browser runner 1
   Loaded: loaded (/etc/systemd/system/[email protected]; static; vendor preset: enabled)

In this code state try start start/stop only for service unittypes, but In my example it's need doing and for target unittypes. I think can be done like this:

-      {% if unittype == 'service' %}
-        {% set activation_status = unitconfig.status if unitconfig.status is defined and unitconfig.status == 'start' else 'stop' %}
+      {% if unittype == 'service' or unittype == 'target' %}
+      {% if unitconfig.status is defined %}
        {% set activation_status = unitconfig.status if unitconfig.status == 'start' else 'stop' %}
systemd_systemd_units_activate_or_deactivate_{{ unit }}_{{ unittype }}:
  cmd.wait:
    - name: systemctl {{ activation_status }} {{ unit }}.{{ unittype }}
...
+     {% endif %}

In pillar explicitly define status variable.

unix196 avatar Jan 13 '21 04:01 unix196

Also timer units would be ideal

B1ue-W01f avatar Jun 18 '21 17:06 B1ue-W01f