【linux】设置开启自启脚本时问题
linux开启自启
/etc/rc.d/rc.local
脚本不生效。
查询攻略,说是脚本问题、时序问题等等,排除脚本问题,然后使用
journalctl -u rc-local.service
命令,查询开启自启报错日志
-- Logs begin at Thu 2023-12-14 16:07:48 CST, end at Thu 2023-12-14 16:08:56 CST. --
Dec 14 16:08:01 localhost.localdomain systemd[1]: Starting /etc/rc.d/rc.local Compatibility...
Dec 14 16:08:04 localhost.localdomain rc.local[1238]: Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
Dec 14 16:08:04 localhost.localdomain rc.local[1238]: At least one of these environment variable is needed to run this program
Dec 14 16:08:04 localhost.localdomain systemd[1]: rc-local.service: control process exited, code=exited status=1
Dec 14 16:08:04 localhost.localdomain systemd[1]: Failed to start /etc/rc.d/rc.local Compatibility.
Dec 14 16:08:04 localhost.localdomain systemd[1]: Unit rc-local.service entered failed state.
Dec 14 16:08:04 localhost.localdomain systemd[1]: rc-local.service failed.
忽略了第二行和第三行,从第三行查起,没查出什么,然后从第二行查起,说是缺少环境变量,查了下/etc/profile,有变量
说是时序问题,然后在rc.local的每个脚本命令前打印日志,也还是没发现问题,然后调了下jdk中JAVA_HOME在path的位置,放在前面了
#export PATH=$PATH:$JAVA_HOME/bin
export PATH=$JAVA_HOME/bin:$PATH
再在每个脚本后面打印日志,发现问题解决了,可能就是时序问题