As far as I can tell from the documentation of systemd, Wants=
and WantedBy=
perform the same function, except that the former is put in the dependent unit file and vice-versa. (That, and WantedBy=
creates the unit.type.wants
directory and populates it with symlinks.)
From DigitalOcean: Understanding Systemd Units and Unit Files:
The
WantedBy=
directive... allows you to specify a dependency relationship in a similar way to theWants=
directive does in the[Unit]
section. The difference is that this directive is included in the ancillary unit allowing the primary unit listed to remain relatively clean.
Is it really just about keeping a unit file "clean"? What is the best practice for using these two directives? That is, if service alpha "wants" service beta, when should I use Wants=beta.service
in alpha.service
and when should I prefer WantedBy=alpha.service
in the beta.service
?