centos7 shell脚本开机自启动

尝试了各种自启动,以下方式是唯一有效的

 

一.  编辑脚本

 内容如下示例:

==================== startCrontab.sh ===================
#!/bin/sh
#chkconfig: 2345 90 10
#description:auto_run

cd /opt/swsk/shellCmd
python3 sh_krbInit.py > nohup.log 2>&1 &
ps -ef | grep pyCrontab.py | awk '{print $2}' | xargs kill -9
python3 pyCrontab.py > nohup.log 2>&1 &
========================================================

chkconfig参数说明:
>> 上面的 2345 是启动级别,参考如下

  ****************** 对各个运行级的详细解释 ****************#

  缺省的运行级,RHS用到的级别如下:

  0:关机

  1:单用户模式

  2:无网络支持的多用户模式

  3:有网络支持的多用户模式

  4:保留,未使用

  5:有网络支持有X-Window支持的多用户模式

  6:重新引导系统,即重启

  *********************************************************

>> 上面的 90 是启动优先级, 优先级范围是0-100,数字越大,优先级越低。
>> 上面的 10 是停止优先级, 优先级范围是0-100,数字越大,优先级越低。


二. 相关定时任务的脚本加入自启动
1. 将脚本拷贝到/etc/rc.d/init.d目录下
cp /opt/swsk/shellCmd/startCrontab.sh /etc/rc.d/init.d

2. 增加脚本的可执行权限
chmod +x /etc/rc.d/init.d/startCrontab.sh

3. 添加脚本到开机自动启动项目中
cd /etc/rc.d/init.d
chkconfig --add startCrontab.sh
chkconfig startCrontab.sh on

三. 重启测试


让火焰净化一切
原文地址:https://www.cnblogs.com/icefoxhz/p/13677393.html