The best way to start the jar package project under Centos7 server
- 2021-01-03 21:15:18
- OfStack
preface
Anyone can run the jar package on linux. Why do I have to do this alone? Attentive friends may have found the keywords Centos7 and the best way in the title.
This shows that I am not just writing something water 1 blog. ° & # 8711; ° & # 9677;) The & # 65417; The & # 65438;
First of all, Centos7 recommends that we run the project this way
First execute the command:
cd /ets/systemd/system
Go to this directory and create a new yourProjectName.service to set yourProjectName to the name of the service you think of
Edit 1 new file with vi
vi yourProjectName.service
The file name
[Unit]
Description=yourProjectName # describe
After=syslog.target network.target # Rely on
[Service]
Type=simple
ExecStart=/usr/bin/java -jar /opt/javaapps/yourProjectName.jar
# The front is java The absolute path of the command The back is jar The absolute path of the package
ExecStop=/bin/kill -15 $MAINPID
User=root
Group=root
[Install]
WantedBy=multi-user.target
use
systemctl start yourProjectName
or
systemctl start yourProjectName.service
You start the service.
If the project is changed:
First run
systemctl daemon-reload
Run again
systemctl start sell.service
If you want to stop service:
systemctl stop yourProjectName
or
systemctl stop yourProjectName.service
Setup Power on:
systemctl enable yourProjectName
or
systemctl enable yourProjectName.service
Or you don't want to boot it up:
vi yourProjectName.service
0
or
vi yourProjectName.service
1
Well, that's it for now. Running the project in a canonical manner helps with later maintenance.
conclusion