reboot后自动重启:
1).编写重启脚本 auto_start.sh:
代码如下:
#!/bin/sh
export JAVA_HOME=/app/jdk1.8.0_73
export JRE_HOME=/app/jdk1.8.0_73/jre
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=./:$JAVA_HOME/lib:$JRE_HOME/lib
#start tomcat
echo "sleep 120 s" >> /app/service_shells/startrecord.log
sleep 120 s
echo "tomcat01 start ...">> /app/service_shells/startrecord.log
su dasuser -s /app/tomcat01/bin/startup.sh >> /app/service_shells/startrecord.log
echo "tomcat02 start ...">> /app/service_shells/startrecord.log
su dasuser -s /app/tomcat02/bin/startup.sh >> /app/service_shells/startrecord.log
echo "sleep 100S">> /app/service_shells/startrecord.log
#start nginx
sleep 100
echo "nginx start...">> /app/service_shells/startrecord.log
/app/nginx-1.10.0/sbin nginx >>/app/service_shells/startrecord.log
##su devuser -s /app/tomcat02/bin/startup.sh >> /app/service_shells/startrecord.log
#start ORACLE
touch /var/lock/subsys/local
su - oracle -lc "/app/oracle/product/11.2.0.4/bin/lsnrctl start"
su - oracle -c "/app/oracle/product/11.2.0.4/bin/dbstart"
说明:
1.其中 ">>"表示文本末尾追加输出日志,">"表示覆盖原日志
2.如果需要切换用户执行脚本,添加 su devuser -s ,表示切换到用户devuser ,-s 表示引用切换之前的用户的环境变量,s 表示切换成devuser 的环境
##su devuser -s /app/tomcat02/bin/startup.sh >> /app/service_shells/startrecord.log
3.sleep XX 表示休眠XX时间后执行
4.注意赋予用户对 auto_start.sh 的执行权限 sudo a+x /app/service_shells/auto_start.sh
2).编辑 文件 rc.local 在exit 0 前添加需要启动的脚本 auto_start.sh,该脚本的目录为 /app/service_shells/
cd /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
/app/service_shells/auto_start.sh
exit 0
编辑保存rc.local,同时赋予执行权限 sudo a+x /etc/rc.local