The following is my practice, for your reference.
Not sure it's also suitable for your environment.
*.Please pay attention to whether the firewall has opened the port you want to use.
0. my environment:
Oracle Cloud Free Tier VPS: Ubuntu 20.04.3 LTS
My web-app in /home/ubuntu/b4jwebhook/WebHook.jar
1.create mywebhook.service file:
sudo vim /etc/systemd/system/mywebhook.service <Enter>
2. The content of mywebhook.service is as follows:
[Unit]
Description=This is my webhook
After=network.target
[Service]
# User=user
# Group=group
WorkingDirectory=/home/ubuntu/b4jwebhook
ExecStart=sh /home/ubuntu/b4jwebhook/webhookrun.sh
Restart=always
RestartSec=3s
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
3.After the file is created, execute the following command:
sudo chmod 755 /etc/systemd/system/mywebhook.service <Enter>
sudo systemctl daemon-reload<Enter>
sudo systemctl enable mywebhook.service<Enter>
4.create webhookrun.sh file:
sudo vim /home/ubuntu/b4jwebhook/webhookrun.sh <Enter>
5. The content of webhookrun.sh is as follows:
nohup sudo java -jar WebHook.jar &
6.After the file is created, execute the following command:
sudo chmod 755 /home/ubuntu/b4jwebhook/webhookrun.sh <Enter>
7.Ok. Now reboot the VPS, The web server is autostart.