您当前的位置: 首页 >  Java

qq_34412985

暂无认证

  • 2浏览

    0关注

    1061博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

关于在rc.local中放入Java程序无法开机自启的问题

qq_34412985 发布时间:2020-06-13 17:32:29 ,浏览量:2

今天公司服务器因为断电重启发现了一个问题——所有部署了springboot打的jar包的服务器在重启后没有自动将服务启动起来。但是rc.local文件是有可执行权限的,而且单独执行该文件中的条目可以正常启动服务,那么问题会在哪里呢?

在jar启动脚本后面加上了重定向生成一个启动日志或者通过ps -ef|grep jar查进程看看: 1/usr/local/bin/tomcat/bin/startup.sh>>/tmp/startup.log 结果发现日志提示找不到环境变量JAVA_HOME,但是该环境变量我们明确是写进了/etc/profile中,重新source后再重启,发现服务依然没有启动,这是为什么呢?查看/etc/rc.local文件的描述信息:

#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 contrast 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.

发现该文件是在所有服务之前运行,所以/etc/profiles或bashrc里的环境变量这个时候根本没有执行,因此环境变量自然无法生效导致服务启动报错了,解决办法就是在/etc/rc.local中加入环境变量,如图: 在这里插入图片描述 脚本中对应的内容: 在这里插入图片描述

关注
打赏
1653291990
查看更多评论
立即登录/注册

微信扫码登录

0.0405s