CentOS6的/etc/rc.local不执行的问题解决
小编在一个场景下,希望java -jar abc.jar
命令在系统开机自启动是自动执行,于是乎在文件/etc/rc.local中写入nohup java -jar abc.jar &
,重启后发现竟然此进程没有在后台运行,在网上gg一段时间,检查了/etc/rc.local的文件权限,没问题,有执行权限,也尝试过这位老兄重新生成该文件的方案,http://blog.fcc.qinggl.com/page-17847.html;但问题依旧。经过一段时间的排查,猜想是否是该文件没有加载到某些重要的东西,首先想到的是环境变量,于是乎将文件的解释器#!/bin/sh
修改为#!/bin/bash
,然后在文件中手动加载环境变量PATH=/usr/local/jdk1.8.0_144//bin:/usr/local/jdk1.8.0_144//bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
,然后重启,诶,发现后台有java -jar abc.jar`的进程了,以下贴上/etc/rc.local文件内容,仅供参考:
#!/bin/bash
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
PATH=/usr/local/jdk1.8.0_144/bin:/usr/local/jdk1.8.0_144/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
touch /var/lock/subsys/local
setsid java -jar abc.jar &