Is there a way to dynamically assign environment variables in a systemd service unit file?
We have a machine that has 4 GPUs, and we want to spin up multiple instances of a certain service per GPU. E.g.:
- ad nauseam
So the 1:1, 2:1, etc. are effectively the %i in the service unit file.
In order for the service to bind to a particular GPU, the service executable checks a certain environment variable, e.g.:
Is there a way I can take %i inside the service unit file and run it through some (shell) function to derive the GPU number, and then I can set the USE_GPU environment variable accordingly?
Most importantly, I don't want the hassle of writing multiple
/etc/systemd/system/gpu_service@x:y.service/local.conf files just so I can spin up more instances.