[步骤] Linux 开机自启 (通过 chkconfig 实现)

案例一:添加一个受 chkconfig 管理的服务(脚本)
1.1 编写一个脚本

# vim /etc/init.d/start.sh

创建以下内容:

#!/bin/bash
systemctl start httpd

# chkconfig: 345 85 15
# description: This is a script of starting httpd

(补充:chkconfig:后面的 3 个含义为 httpd 的级别为 3、4 和 5,启动序号为 85,关闭序号为 15)

1.2 给脚本添加执行权限

# chmod +x /etc/init.d/start.sh

1.3 将脚本添加到 chkconfig 中

# chkconfig --add start.sh

1.4 显示刚刚添加到 chkconfig 的应用

# chkconfig --list

案例二:通过 chkconfig 管理一个服务或脚本
2.1 设定 start.sh 在 3 和 5 等级为 on

# chkconfig --level 35 start.sh on

2.2 设定 start.sh 在各等级为 on,“各等级”包括 2、3、4、5 等级

# chkconfig start.sh on

2.3 设定 start.sh 在各等级为 off,“各等级”包括 2、3、4、5 等级

# chkconfig start.sh off

[步骤] openSUSE & SLE 开机自启

内容一:openSUSE & SLE 开机设置文档介绍

1) /etc/init.d/boot.local
2) /etc/init.d/halt.local
3) /etc/init.d/before.local
4) /etc/init.d/after.local


补充:
1) 其中的 boot.local 是在刚开机时,在所有其他的程序执行前执行的文件
2) 其中的 after.local 是在刚开机后,在所有其他的程序执行后执行的文件

(注意:上面第三和第四个档案默认是不存在的,可以自己创建一个, 就像写个 shell 一样很简单)

内容二:设置 openSUSE & SLE 开机自启命令的案例
2.1 创建 after.local 文件

# vim /etc/init.d/after.local

创建以下内容:

sudo systemctl restart httpd

(补充:这里以开机自启 httpd 程序为例)

2.2 给 after.local 文件执行权限

# chmod u+x /etc/init.d/after.local