服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

Linux|Centos|Ubuntu|系统进程|Fedora|注册表|Bios|Solaris|Windows7|Windows10|Windows11|windows server|

服务器之家 - 服务器系统 - Centos - CentOS7设置jar应用程序开机启动的方法

CentOS7设置jar应用程序开机启动的方法

2022-08-01 10:13CaedmonJiang Centos

这篇文章主要介绍了CentOS7设置jar应用程序开机启动的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

项目部署时遇到坑

在部署zhihudemo时,没有用Jenkins这种自动化部署工具,在linux centos中部署jar包项目时遇到一个坑,通过xshell远程连接服务器,在系统中使用“java -jar”命令启动jar包时,输出日志会占据当前终端页面,如果关闭终端窗口的话,整个java程序就将停止,为了解决这个问题,可以将jar包设置为后台服务,并进一步设置为系统服务和开机自启

1. 编写启动脚本

脚本存放位置随意,本例保存在了/etc/rc.d/init.d/file-preview-server.sh

?
1
2
3
4
5
6
7
8
9
# !/bin/bash
# program
# file preview server start
 
export JAVA_HOME=/opt/jdk8
export JRE=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib:$JRE/lib:.
export PATH=$JAVA_HOME/bin/:$JRE/bin:$PATH
nohup java -jar /root/file-preview-server/file-preview-server.jar > /root/file-preview-server/stdout.log &

2. 给/etc/rc.d/init.d/file-preview-server.sh文件添加执行权限

?
1
chmod +x /etc/rc.d/init.d/file-preview-server.sh

3. 给/etc/rc.d/rc.local文件添加执行权限

?
1
chmod +x /etc/rc.d/rc.local

4. 编辑/etc/rc.d/rc.local文件

在文件末尾添加如下语句

?
1
su - root -c '/etc/rc.d/init.d/file-preview-server.sh'

至此,大功告成!

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://www.jianshu.com/p/4b391b88ac9c

延伸 · 阅读

精彩推荐