Interview Prep/Linux/Processes, services and systemd

You need two instances of the same worker service with different config on one host. How?

IntermediateScenarioProcesses, services and systemd
Answer

Situation read → systemd template units.

What I'd do → Create /etc/systemd/system/[email protected]:

[Service]
User=worker
EnvironmentFile=/etc/worker/%i.env
ExecStart=/opt/worker/bin/worker --queue %i
Restart=on-failure

[Install]
WantedBy=multi-user.target

Then:

sudo systemctl enable --now worker@emails worker@reports
systemctl status 'worker@*'

Why → %i is replaced with the instance name, so one file serves any number of instances.

Interview tip → Templates are also how getty@tty1 and openvpn@client work.

All Linux questions Roadmap: Linux

More on Processes, services and systemd