以统一方式调用 SysV init 脚本,systemd 系统上会转发给 systemctl。
/usr/sbin/service 是兼容层:它清理环境变量后执行 /etc/init.d/<name>,接受 start、stop、restart、reload、status 等动作。systemd 发行版上,同名脚本通常被替换为转发到 systemctl,所以 service ssh restart 实际走 unit。
它只覆盖有 init 脚本或同名 unit 的服务,不负责 enable/disable(systemd 下用 systemctl enable),也不保证脚本名与 unit 名一致。Debian 的 service --status-all 列出 init 脚本状态;RHEL 系更推荐直接用 systemctl。
# 查看所有 SysV 服务状态(Debian 系)
service --status-all
# 重启 SSH 并查看状态
service ssh restart
service ssh status
# systemd 系统上的显式等价写法
systemctl restart sshd
sshd,Debian 是 ssh,用 systemctl list-unit-files 'ssh*' 确认。service network restart 在 NetworkManager 系统上会失败或断开管理,改用 nmcli 或重启 NetworkManager。--status-all 只显示 init 脚本,[ ? ] 表示脚本不支持 status,不代表服务异常。systemctl status 和 journal。合上页面,先回答,再展开对照。
service 命令实际做了什么?service 负责 enable/disable 吗?service --status-all 显示 [ ? ] 表示什么?systemctl unit。systemctl enable/disable。
小程序版
微信扫码,随时查命令