阅读此文章之前,我们来约定一下:system.service是服务
温馨提示:修改启动脚本之后记得执行systemctl daemon-reload重新加载哦~
1.查看开机启动项
ll /etc/systemd/system/multi-user.target.wants // service(全部)
systemctl list-unit-files (--type=service) // systemctl(全部)
systemctl list-unit-files | grep enabled // systemctl(自启动)
chkconfig --list // service(安装)
systemctl --failed // 查看启动失败的服务
2.system.service命令
systemctl daemon-reload // 当新增或修改service单元文件时,需要系统重新加载所有修改过的配置文件
systemctl enable system.service // 设置为开机自启动
systemctl is-enabled system.service // 查看服务是否开机启动
systemctl disable system.service // 关掉开机启用
systemctl list-unit-files --state=enabled // 查看所有开机自启动服务
systemctl start system.service // 启动服务
systemctl stop system.service // 关闭服务,关闭服务后,进程会全部被kill掉
systemctl status system.service // 查看服务的状态
systemctl restart system.service // 重启服务,先stop,再start
systemctl kill system.service // 杀死一个服务的所有子进程
systemctl reload system.service // 重新加载一个服务的配置文件
systemctl cat system.service // 查看服务配置文件
systemctl reset-failed system.service // 移除标记为丢失的Unit文件。在删除Unit文件后,由于缓存的关系,即使通过daemon-reload更新了缓存,在list-units中依然会显示标记为not-found的Unit
systemd-analyze // 系统启动单元模块花费时间
systemd-analyze blame // 系统启动每个单元花费时间
systemd-analyze critical-chain // 系统启动花费最长时间单元