systemctl 学习笔记

systemctl 快速入门

systemctl 用来取代旧的 service 和 chkconfig 命令。

几个主要路径:

  • /etc/systemd/system.conf
  • /usr/lib/systemd/system/ PRM 安装的 systemd unit 文件
  • /run/systemd/system/ Systemd 运行时创建的文件
  • /etc/systemd/system/systemctl enable 创建的文件

Systemd unit 文件类型:

  • .service
  • .target 一组 systemd units
  • .socket

在使用 systemctl 命令时,默认是 .service 后缀的文件,以下两个命令等效:

$ sudo systemctl start httpd.service
$ sudo systemctl start httpd

用 systemctl 替代 service

对比过时的 service 系列命令:

service 命令 systemctl 命名
service name start systemctl start name.service
service name stop systemctl stop name.service
service name restart systemctl restart name.service
service name condrestart systemctl try-restart name.service
(Restarts a service only if it’s running)
service name reload systemctl reload name.service
(Reloads configure)
service name status systemctl status name.service
systemctl is-active name.service
service --status-all systemctl list-units --type service --all

用 systemctl 替代 chkconfig

对比过时的 chkconfig 系列命名:

chkconfig 命令 systemctl 命名
chkconfig name on systemctl enable name.service
chkconfig name off systemctl disable name.service
chkconfig --list name systemctl status name.service
systemctl is-enable name.service
chkconfig --list systemctl list-unit-files --type service