Centos 设置服务开机自启动

一、systemctl是一个系统管理守护进程、工具和库的集合,
用于取代system、service 和 chkconfig 命令,
初始进程主要负责控制systemd系统和服务管理器。

通过systemctl -help可以看到该命令主要分为:
查询或发送控制命令给systemd服务,
管理单元服务的命令,
服务文件的相关命令,任务、环境、快照相关命令,
systemd服务的配置重载,系统开机关机相关的命令。

1. 列出所有可用单元 

# systemctl list-unit-files

2. 列出所有运行中单元 

# systemctl list-units

3. 查看已启动的服务

systemctl list-units --type=service

4. 列出所有失败单元 

# systemctl –failed

5. 检查某个单元(如 docker.service)是否启用 

[root@cloud-container ~]# systemctl is-enabled docker.service
enabled


6. 列出所有服务 

# systemctl list-unit-files –type=service

7. 查看是否设置开机启动
systemctl list-unit-files | grep enable

8. 设置开机启动
systemctl enable docker.service

9. 关闭开机启动
systemctl disable docker.service

 

二、docker容器设置自动启动

[root@cloud-container docker]# chkconfig docker.service on
error reading information on service docker.service: No such file or directory
[root@cloud-container docker]# chkconfig docker on
Note: Forwarding request to 'systemctl enable docker.service'.
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@cloud-container docker]#
[root@cloud-container docker]# systemctl enable docker.service
[root@cloud-container docker]#
[root@cloud-container ~]# systemctl list-unit-files | grep enable | grep docker
docker.service                                enabled
[root@cloud-container ~]#

 

你可能感兴趣的:(docker)