添加可执行属性:chmod +x autorun.sh。 注:chkconfig第一列表示运行等级,一般 2345 即可。后2个分别是启动优先级和停止优先级(细节待查),数值越大,优先级越低。 注1:必须依上述格式,否则在添加服务时会提示service autorun.sh does not support chkconfig。
添加到系统启动
在 /etc/rc.d/init.d 目录,执行:
1 2
chkconfig --add autorun.sh chkconfig autorun.sh on
完成。
实例
在系统启动时,更新docker,并将日志重定向到指定目录。脚本 autorun.sh 如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
kconfig:2345 80 90 #decription:autostart
echo "my run" 2>&1 | tee -a /tmp/dockerlog.txt
out_alg=$(echo 123456 | sudo -S docker pull registry.cn-hangzhou.aliyuncs.com/latelee/busybox 2>&1 | tee -a /tmp/dockerlog.txt)
if [[ $out_alg == *"Downloaded newer image"* ]]; then echo "update alg image ok." 2>&1 | tee -a /tmp/dockerlog.txt else echo "alg Image is up to date or other unknow result." 2>&1 | tee -a /tmp/dockerlog.txt fi