目录
一、将sh文件写入/etc/rc.d/rc.local(最终失败了,这个文件死活开机不运行,知道的道友麻烦教一下)
#!/bin/bash
# 1. 检查程序的运行状态,避免重复启动
kill_pid=`ps -ef | grep java | grep "SESAN_YN_public_health-1.0.0" | grep -v grep | awk '{print $2}'`
if [ -n "${kill_pid}" ]
then
echo "pid = "${kill_pid}
echo "SESAN_YN_public_health-1.0.0 程序正在运行中,请勿重复启动"
exit 1
fi
# 2. nohup 后台运行脚本
nohup java -jar /usr/local/etc/SESAN_YN_public_health-1.0.0.jar >nohup.out 2>&1 &
# 3. 显示日志
tail -200f ./nohup.out
$ cd /home/java
chmod +x start.sh
$ vim /etc/rc.d/rc.local
/home/java/start.sh
chmod +x /etc/rc.d/rc.local
$ sudo reboot
$ crontab -e
@reboot /home/java/start.sh
这样我运行还是失败:失败原因通过cat查看错误日志
$ cat /var/spool/mail/root
错误原因:找不到java环境
nohup: failed to run command ‘java’: No such file or directory
运行jar包前 source /etc/profile
# 2. nohup 后台运行脚本
source /etc/profile
nohup java -jar /usr/local/etc/SESAN_YN_public_health-1.0.0.jar >nohup.out 2>&1 &