systemctl restart、reload 与 try-restart 的区别

正确重启 systemd 服务:完整重启、仅重载配置,还是仅在运行中才重启。

Linux命令systemd服务中风险
运行 sudo systemctl restart nginx 停止并重新启动服务;如果服务支持不中断连接地重载配置,改用 sudo systemctl reload nginx。

01命令

命令
$ systemctl restart nginx

02作用说明

restart 会先停止单元再启动,进程被完全替换,所有连接都会中断。reload 则要求正在运行的进程重新读取配置而不停止(仅在单元定义了 reload 选项时有效,如 nginx);try-restart 只在单元当前处于活动状态时重启,停止状态下什么也不做。还有一个方便的组合 reload-or-restart:能重载就重载,否则重启。注意这些命令都不会改变服务是否开机自启——那由 enable/disable 控制。

03风险

风险中风险
使用条件Root privileges (sudo) for system units
!注意: 如果服务重启失败,先用 systemctl status <单元> 和 journalctl -u <单元> 查看原因;失败的单元会一直留在列表中,直到 systemctl reset-failed。

04撤销

撤销
$ systemctl start nginx

05来源

  • systemctl(1) — Arch Linux manual
    man.archlinux.org · technical · 2026-09-17
    依据: "restart ... Stop and then start one or more units"; "reload ... Asks all units listed on the command line to reload their configuration"; "try-restart ... Restart one or more units if active". The page also documents reload-or-restart.
  • Ubuntu Manpage: systemctl - Control the systemd system and service manager
    manpages.ubuntu.com · technical · 2026-09-17
    依据: "restart NAME... — Stop and then start one or more units"; "reload NAME... — Asks all units listed ... to reload their configuration"; "try-restart NAME... — Restart one or more units if active".

最后验证: 2026-09-19 · 分类: 系统与设置

06相关方案