I know that systemd provides an excellent mechanism to override a package-provided unit file to influence the service configuration/behavior. This is typically done by using the below command
sudo systemctl edit <unitfile>
to create an override conf file at
Systemd also provides a separate mechanism to define a template unit file, and have it instantiated to create instance-specific units at runtime. This requires naming the template file as
and then instantiating it as
systemctl start <servicename>@<instancename>
Now, I have a situation where I would like to run a package-provided service as multiple unit instances. I want to avoid creating my own template unit file, so I am trying to see if the package-provided unit file can be overriden to create the template unit file.
Since, per my understanding, the template unit file has a naming convention that is different from the regular unit file, I think I cannot override the package-provided unit file with a template file by placing it in /etc/systemd/system.
Is there any defined way to achieve what I am trying to do?
Specific scenario: The grafana package installs a grafana-server.service unit file. I want to run two instances of grafana on my machine - one each for DEV and STG. I have been able to do this:
- modify the grafana-server.service file (using %I to set folder locations & file paths)
- rename the modified grafana-server.service to grafana-server@.service
start instances of grafana by using:
sudo systemctl start grafana-server@dev
sudo systemctl start grafana-server@stg
However, this breaks the link from the grafana provided service unit file, and if they enhance the service file when I upgrade, I will need to redo this activity again. My objective is to avoid this direct dependency, and instead convert it to an override dependency.