Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
unix196 opened this issue Jan 13, 2021 · 1 comment
Open
Labels
bug Something isn't working

Comments

@unix196
Copy link

unix196 commented Jan 13, 2021

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
Wants=browser-runner@1.service
Wants=browser-runner@2.service
Wants=browser-runner@3.service

systemctl cat browser-runner@.service
[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 browser-runner@.service
systemctl  is-enabled browser-runner.target

systemctl  status browser-runner@.service
Failed to get properties: Unit name browser-runner@.service is missing the instance name.

systemctl  status browser-runner@1.service
● browser-runner@1.service - Browser runner 1
   Loaded: loaded (/etc/systemd/system/browser-runner@.service; 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 unix196 added the bug Something isn't working label Jan 13, 2021
@B1ue-W01f
Copy link

Also timer units would be ideal

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants