假设您有一个JAR文件,需要将其作为服务运行。此外,如果系统重新启动,您希望它自动启动。
Ubuntu具有内置的机制来创建自定义服务,从而使它们能够在系统启动时启动并作为服务启动/停止。在本文中,我将分享一种简单优雅的方法来为JAR文件创建服务包装,以便您可以将其作为服务运行。开始了。
步骤1:建立服务
sudo vim /etc/systemd/system/my-webapp.service
将以下内容复制/粘贴到文件中/etc/systemd/system/my-webapp.service:
[Unit]
Description=My Webapp Java REST Service
[Service]
User=ubuntu
The configuration file application.properties should be here:
#change this to your workspace
WorkingDirectory=/home/ubuntu/workspace
#path to executable.
#executable is a bash script which calls jar file
ExecStart=/home/ubuntu/workspace/my-webapp
SuccessExitStatus=143
TimeoutStopSec=10
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
步骤2:创建Bas