1. 装置 jdk
apt install openjdk-11-jdk
2. 创立服务配置文件
vim /ect/systemd/system/my_service.service
追加以下内容
[Unit]
Description=My Java Service
[Service]
User=ubuntu
WorkingDirectory=/home/ubuntu/server
ExecStart=/usr/bin/java -jar /home/ubuntu/server/main.jar
SuccessExitStatus=143
TimeoutStopSec=10
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
3. 更新、运行、启动服务配置
systemctl daemon-reload
systemctl enable my_service.service
systemctl start my_service.service