java - linux系统重启后自启动jar程序失败
PHP中文网
PHP中文网 2017-04-18 10:18:08

linux系统在rc.local中设置了两行命令分别用来启动tomcat和一个jar程序,重启之后,
tomcat成功启动,但是启动jar程序的命令没有被执行,上代码:

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In constrast to previous versions due to parallel execution during boot 
# this script will NOT be run after all other services.
#  
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
export JAVA_HOME=/opt/jdk/jdk1.8.0_111
/root/test/apache-tomcat-8.5.6/bin/startup.sh
nohup java -jar /root/test/myjava.jar &
touch /var/lock/subsys/local

是不是nohup命令在启动的时候也需要设置一些环境变量呢,还是说执行jar程序单单一个JAVA_HOME配置不够呢

PHP中文网
PHP中文网

认证0级讲师

全部回覆(1)
PHPzhong

linux下面的servicechkconfig可以结合使用。
我给你我的启动脚本吧,内容请自行修改:

# cat /etc/rc.d/init.d/tomcat 
#!/bin/sh
# Tomcat init script for Linux.
#
# chkconfig: 2345 96 14
# description: The Apache Tomcat servlet/JSP container.
 JAVA_HOME=/usr/java/latest
 CATALINA_HOME=/apps/srv/tomcat
 JAVA_OPTS="-Xms1200m -Xmx1200m -XX:NewSize=512m -XX:MaxNewSize=512m -XX:PermSize=256m -XX:MaxPermSize=256m"
 export JAVA_HOME CATALINA_HOME JAVA_OPTS
case $1 in
restart)
    $CATALINA_HOME/bin/catalina.sh stop
    sleep 2
#    exec $CATALINA_HOME/bin/catalina.sh start 
    exec /bin/su -c "$CATALINA_HOME/bin/catalina.sh start" tomcat
    ;;
start)
    exec /bin/su -c "$CATALINA_HOME/bin/catalina.sh start" tomcat
    ;;
*)
   exec $CATALINA_HOME/bin/catalina.sh $1
   ;;
esac

这个脚本可以实现 service tomcat {start|status|stop|restart....}

chkconfig: 2345 96 14 这行还可以实现 $ chkconfig tomcat on

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!