systemd 将过去所谓的 daemon 执行脚本通称为一个服务单位(unit),而每种服务单位依据功能来区分,就分类为不同的类型(type)
配置文件:
systemctl [command] [unit]
# command 主要有:
start # 立刻启动后面接的 unit
stop # 立刻关闭后面接的 unit
restart # 立刻关闭后启动后面接的 unit,亦即执行 stop 再 start 的意思
reload # 不关闭后面接的 unit 的情况下,重载配置文件,让设定生效
enable # 设定下次开机时,后面接的 unit 会被启动
disable # 设定下次开机时,后面接的 unit 不会被启动
status # 目前后面接的这个 unit 的状态,会列出有没有正在执行、开机预设执行否、登录等信息等
is-active # 目前有没有正在运作中
is-enable # 开机时有没有预设要启用这个 unit
systemctl [command] [--type=TYPE] [--all]
command:
list-units # 依据 unit 列出目前有启动的 unit 。若加上 --all 才会列出没启动的
list-unit-files # 依据 /usr/lib/systemd/system/ 内的文件,将所有文件列表说明
--type=TYPE # 就是之前提到的 unit type。主要有 service,socket,target等
systemctl [command] [unit.target]
command:
get-default # 取得目前的target
set-default # 设定后面接的target成为默认的操作模式
isolate # 切换到后面的模式
systemctl poweroff # 系统关机
systemctl reboot # 重新启动
systemctl suspend # 进入暂停模式
systemctl hibernate # 进去休眠模式
systemctl rescue # 强制进去救援模式
systemctl emergency # 强制进入紧急救援模式
systemctl list-dependencies [unit] [--reverse]
--reverse # 反向追踪谁使用这个unit的意思