systemctl
可以实现的远不止你提到的这些,还有:
- systemd向后兼容SysV。
- 并行加载服务
- 它提供按需激活服务
- 它基于依赖关系
- 我认为还有更多...
systemd
使用单元(unit)进行工作,有不同类型的单元:目标(target),服务(service),套接字(socket)等。 目标和运行级别(runlevel)的概念相同,它们是一组单元。
您可以使用systemctl
设置或获取默认系统目标。
systemctl get-default
你可以进入其他目标。
systemctl isolate multiuser.target
其他目标包括:多用户、图形化、救援、紧急、重启和关机。
正如你所说,你可以使用
systemctl
来管理服务,我还知道一些与服务管理相关的其他命令,它们包括:
# Restarts a service only if it is running.
systemctl try-restart name.service
# Reloads configuration if it's possible.
systemctl reload name.service
# try to reload but if it's not possible restarts the service
systemctl reload-or-restart name.service
你可以使用它来了解服务的状态。
systemctl status name.service
systemctl is-active name.service # running
systemctl is-enabled name.service # will be activated when booting
systemctl is-failed name.service # failed to load
您可以对服务进行屏蔽或取消屏蔽:
systemctl mask name.service
systemctl unmask name.service
当你屏蔽一个服务时,它将与
/dev/null
链接,因此其他服务无法手动或自动激活/启用它(你应该先取消屏蔽)。
systemctl的另一个用途是列出单元:
systemctl list-units
列出所有类型的单位,已加载并处于活动状态。
服务单位列表:
systemctl list-units --type=service
或者列出所有可用的单位,而不仅仅是已加载和激活的单位。
systemctl list-unit-files
您可以创建别名甚至控制远程机器。
systemctl --host ravexina@192.168.56.4 list-units
另一方面,
服务
只做它应该做的事情,管理服务,与他人的事务无关 ;)