Is it possible to override a systemd unit file to create a template unit file?

For both options below, first override the grafana-server.service (without the @) on /etc/systemd/system and suppress ExecStart (supposing it uses that) to make it starts nothing. On /etc/systemd/system/grafana-server.service.d/10-disable-execstart.conf:

[Service]
ExecStart=
WorkingDirectory=/path/to/your/confdir

Option 1 - Overriding with generic instances

Create a [email protected] that corresponds to your settings with the following configuration to [Unit] and [Service]:

[Unit]
PartOf=grafana-server.service
ReloadPropagatedFrom=grafana-server.service

These should bind grafana-server start/stop/restart to all your instances together. The magic is not very well documented, but if you put <instance_name>.conf files on your /path/to/your/confdir, all those instances will be bound automagically!

Option 2 - Overriding specific instances to keep package config

If you want to keep all update goodness from package service file, but accept mainaining custom instances options, create a symbolic link for each instance name from generic

/lib/systemd/system/grafana-server.service

to

/etc/systemd/system/grafana-service@<instance>.service

and then override only the specific options of that instance using

/etc/systemd/system/grafana-server@<instance>.service.d/99-my-options.conf

Make sure to add the following configuration to [Unit] and [Service] to 99-my-options.conf:

[Unit]
PartOf=grafana-server.service
ReloadPropagatedFrom=grafana-server.service

This will assume for each instance all grafana-server.service options and will override them with all options on 99-my-options.conf file and also bind start/stop/restart actions to grafana-server.service.

On both options, if you run

systemctl start grafana-server.service

all your instances which have a /path/to/confdir/<instance>.conf file will be started. The same apply to stop and restart AND you can always manage them individually by using their grafana-server@<instance> service name.