1、背景
有时候突然断电,服务器重启之后还需要手动一个个启动服务比较麻烦,所以考虑在开机的时候能不能设置自动执行脚本启动
2、步骤
1)编写脚本
以下面这三行开头
#!/bin/sh
#chkconfig: 2345 80 90
#description:auto_run
2)将脚本放到 /etc/init.d/目录下
3)运行脚本
systemctl enable xxx.sh
如果想停止自启动,输入 systemctl disable xxx.sh 即可
注:编写的脚本必须保证在 /etc/init.d/目录下也可执行,之前有遇到编写的脚本里面使用的相对路径,导致脚本放到 /etc/init.d/目录下执行不生效