0

Suppose I have two service units bar@%i.service and baz@%i.service which are both part of target unit foo@%i.target and share many common configuration directives, as seen below. (In reality, I have more than two service units.)

# bar@%i.service

[Unit]
PartOf=foo@%i.target

[Service]
Restart=always
RestartSec=1
StartLimitInterval=0
EnvironmentFile=/srv/foo/env
Environment=PATH=/srv/foo/bin
WorkingDirectory=/srv/foo
ExecStop=/srv/foo/stop

ExecStart=/srv/foo/bar/start
StandardError=append:/srv/foo/bar/stderr
StandardOutput=append:/srv/foo/bar/stdout
# baz@%i.service

[Unit]
PartOf=foo@%i.target

[Service]
Restart=always
RestartSec=1
StartLimitInterval=0
EnvironmentFile=/srv/foo/env
Environment=PATH=/srv/foo/bin
WorkingDirectory=/srv/foo
ExecStop=/srv/foo/stop

ExecStart=/srv/foo/baz/start
StandardError=append:/srv/foo/baz/stderr
StandardOutput=append:/srv/foo/baz/stdout

How can I reduce duplication of configuration directives that are common among all the service unit files? Can the common directives be specified in the target unit file rather than in each service unit file? I considered writing a script to generate the service unit files based on a template, but maybe systemd has a built-in solution?

0 Answers0