本文共 1066 字,大约阅读时间需要 3 分钟。
开机执行脚本
在centos7中增加脚本有两种常用的方法:1.修改/etc/rc.d/rc/local文件并修改配置2.脚本放到/etc/rc.d/init.d目录下并进行配置
以下示例以脚本autostart.sh为例:
#!/bin/bash# description:开机自启脚本# 启动tomcat/usr/local/tomcat/bin/startup.sh
1、赋予自定义脚本可执行权限(/opt/script/autostart.sh是自定义脚本)
chmod +x /opt/script/autostart.sh
2、打开/etc/rc.d/rc/local文件,在末尾增加如下内容
/opt/script/autostart.sh
3、在centos7中,/etc/rc.d/rc.local的权限被降低了,所以需要执行如下命令赋予其可执行权限
chmod +x /etc/rc.d/rc.local
1、将脚本移动到/etc/rc.d/init.d目录下
mv /opt/script/autostart.sh /etc/rc.d/init.d
2、增加脚本的可执行权限
chmod +x /etc/rc.d/init.d/autostart.sh
3、添加脚本到开机自动启动项目中
cd /etc/rc.d/init.dchkconfig --add autostart.shchkconfig autostart.sh on
添加下面两句到 #!/bin/bash 之后。
# chkconfig: 2345 10 90 # description: myservice
注:chkconfig命令对应的目录是/etc/rc.d/init.d文件夹下,需要将自启动脚本拷贝至该文件目录下。
其中2345是默认启动级别,级别有0-6共7个级别。
等级0表示:表示关机
等级1表示:单用户模式
等级2表示:无网络连接的多用户命令行模式
等级3表示:有网络连接的多用户命令行模式
等级4表示:不可用
等级5表示:带图形界面的多用户模式
等级6表示:重新启动
10是启动优先级,90是停止优先级,优先级范围是0-100,数字越大,优先级越低。
转载地址:http://gthwi.baihongyu.com/