CentOS7 sets the method for startup of the jar application

  • 2020-12-09 01:14:44
  • OfStack

Project deployment encountered a pit

When deploying zhihudemo Jenkins not used this deployment automation tools, in linux centos deployment jar bags project met in a pit, through xshell remote connect to the server, use "java - jar" command in the system startup jar packages, output log will occupy the end page, if you close the terminal window, the entire java program will stop, in order to solve this problem, you can set jar package to back-end services, hand in step 1 is set to the system services and boot from the rev

1. Write startup scripts

Script location randomly, this case is stored in the/etc/rc d/init d/file - preview - server. sh


# !/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. Give/etc rc. d/init d/file - preview - server. Add execute permissions sh file


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

3. Give/etc rc. d/rc local file add execute permissions


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

4. Edit/etc rc. d/rc local file

Add the following statement to the end of the file


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

And now we're done!


Related articles: