Para eso están las directivas WantedBy=
y RequiredBy=
en los archivos unitarios systemd
:
WantedBy=, RequiredBy=
This option may be used more than once, or a space-separated list of unit names may be given. A symbolic link is created in the.wants/ or.requires/ directory of each of the listed units when this unit is installed by systemctl enable. This has the effect that a dependency of type Wants= or Requires= is added from the listed unit to the current unit. The primary result is that the current unit will be started when the listed unit is started. See the description of Wants= and Requires= in the [Unit] section for details.
Entonces, el enlace simbólico creado es lo que hace que systemd
inicie la unidad dada cuando se inicia el objetivo/la unidad.
Entonces, por ejemplo:
[Install]
WantedBy=graphical.target
Causaría que la unidad solo se inicie cuando graphical.target
se ejecuta (si la unidad está habilitada ).
Otro ejemplo:
[Install]
WantedBy=my-custom-target.target graphical.target
Haría que la unidad se iniciara cuando se ejecuta my-custom-target.target
o graphical.target
(si la unidad está habilitada ).
Una última cosa a tener en cuenta, puede ser difícil restringir las cosas a un solo objetivo porque algunos objetivos dependen de otros. Por ejemplo, graphical.target
Requires=multi-user.target
, por lo que cuando se inicia graphical.target
, todas las unidades desde multi-user.target
también se inician. Solo tenga en cuenta que algunos objetivos se construyen encima de otros, y que los que se construyen encima obtendrán todo de los objetivos de los que dependen.