Skip to content

Instantly share code, notes, and snippets.

@imerr
Last active September 12, 2018 10:21
Show Gist options
  • Save imerr/2eb1fa929757b3c5a145b208af18b115 to your computer and use it in GitHub Desktop.
Save imerr/2eb1fa929757b3c5a145b208af18b115 to your computer and use it in GitHub Desktop.
Systemd start multiple instances with main control

Template service: /etc/systemd/system/[email protected]

[Unit]
Description=manages the NAME service, instance %i
PartOf=NAME.target

[Service]
Type=simple
User=root
WorkingDirectory=/PATH/TO/SERVICE
ExecStart=./SERVICE
Restart=always
TimeoutStartSec=10
RestartSec=10

[Install]
WantedBy=NAME.target

Dummy service to run the enabled template services: /etc/systemd/system/NAME.target

[Install]
WantedBy=multi-user.target

[Unit]
Description=NAME service

You may then enable multiple instances: systemctl enable NAME@{1..7}.service

the main dummy target: systemctl enable NAME.target

..and finally start the service: systemctl start NAME.target (note: you dont seem to be able to use the service command for this)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment