Apps that come as a main service plus a helper (a worker or a small sidecar script) have an annoying habit: you restart the main one and the helper keeps running with old state. PartOf= ties the helper to its parent.
Put it in the helper’s unit. When systemd stops or restarts the unit you name, it does the same to the helper:
sudo systemctl edit myapp-worker.service
[Unit]
PartOf=myapp.service
After=myapp.service
Now sudo systemctl restart myapp.service restarts myapp-worker.service too, and systemctl stop myapp.service takes both down. On the parent the link shows up the other way round, as ConsistsOf=, which you can check with:
systemctl show -p ConsistsOf myapp.service
That is the one-liner I’d use to see which helpers ride along before restarting something on a server.
The caveat is in the manual’s wording: it is “limited to stopping and restarting”. Starting is not passed on. If myapp.service starts at boot, the worker does not start with it unless something else pulls it in, so give the worker its own WantedBy= in [Install] (or add Wants=myapp-worker.service to the parent). It is also one-way. Restarting the worker leaves the main service alone, which is usually exactly what you want. If you need the stronger “stop me whenever that one goes away for any reason” behaviour, BindsTo= is the setting to read up on.
Further reading: systemd.unit(5) manual page