本文共 893 字,大约阅读时间需要 2 分钟。
1.编写脚本ServiceStart.sh【该脚本对存放对目录没有要求,比如我是存在/opt目录下的】
执行命令:vim ServiceStart.sh
# !/bin/bash# program# test java openexport JAVA_HOME=/opt/java/jdk1.8.0_231export JRE=${JAVA_HOME}/jreexport CLASSPATH=$JAVA_HOME/lib:$JRE/lib:.export PATH=$PATH:$JAVA_HOME/bin/:$JRE/binnohup java -jar /opt/project/aa.jar >/opt/project/log/aa.log &
2.将脚本添加到/etc/rc.local【若没有改文件,则手动创建即可】
#!/bin/sh -e## rc.local## This script is executed at the end of each multiuser runlevel.# Make sure that the script will "exit 0" on success or any other# value on error.## In order to enable or disable this script just change the execution# bits.## By default this script does nothing. bash /opt/ServiceStart.shexit 0
3.修改/etc/rc.local权限
chmod +x /etc/rc.local
4.重新启动【重启服务之前,确保该服务没有人在使用】
reboot
5.重启后查看服务是否正常启动
比如:1)查看Jar运行的信息ps -ef|grep /opt/project/aa.jar2)查看端口状态netstat -nltp|grep port
说明:
我的系统是ubunt18,此文档对centos系统也同样适用。转载地址:http://bfcrf.baihongyu.com/