我知道systemctl enable iptables类似于命令chkconfig –level 5 iptables on,但两者并不完全相同.
使用systemctl,我们如何限制仅在给定目标(如graphical.target)上启动服务.
解决方法:
这就是systemd单元文件中的WantedBy =和requiredBy =指令用于:
从man systemd.unit
开始:
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.
因此,创建的符号链接是导致systemd在目标/单元启动时启动给定单元的原因.
例如:
[Install]
WantedBy=graphical.target
只会在运行graphical.target时启动该单元(如果启用了该单元).
另一个例子:
[Install]
WantedBy=my-custom-target.target graphical.target
当my-custom-target.target或graphical.target运行时(如果启用了该单元),将导致启动该单元.
最后要记住的是,将事物限制在单个目标上可能很困难,因为某些目标依赖于其他目标.例如,graphical.target Requires = multi-user.target,因此当启动graphical.target时,也会启动multi-user.target中的所有单元.请记住,有些目标是建立在其他目标之上的,并且构建在其上的目标将从它们所依赖的目标中获得所有目标.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。