现代 Linux 发行版基本都用 systemd:并行启动、依赖管理、日志和服务生命周期更完整。sysvinit 简单直观,但功能有限,主要用于老系统或极简环境。
| 维度 | systemd | sysvinit |
|---|---|---|
| 启动模型 | unit 依赖图,并行启动 | 顺序执行 init 脚本 |
| 服务定义 | .service unit |
/etc/init.d/ 脚本 |
| 日志 | journald 统一收集 | 各服务自己写日志 |
| 运行级别 | target | runlevel |
| 进程监督 | 自动重启、cgroup 跟踪 | 需额外工具 |
| 兼容 | 提供 sysv 兼容层 | 不支持 systemd unit |
systemctl status app
systemctl enable --now app
systemctl daemon-reload
journalctl -u app -f
systemctl list-dependencies app
daemon-reload,否则 systemctl 仍用旧配置。enable 和 start 是两件事;只 start 不会开机自启。ExecStart 要用绝对路径,环境变量和 WorkingDirectory 要显式配置。systemctl — 服务管理journalctl — 日志service — sysv 兼容入口