23
loading...
This website collects cookies to deliver better user experience
java
command, or it can be deployed and ran as an executable (for example, via SpringBoot), or it can be ran as a service.mvn package
a software suite that provides an array of system components for Linux operating systems. Its main aim is to unify service configuration and behavior across Linux distributions; systemd's primary component is a "system and service manager" - an init system used to bootstrap user space and manage user processes.
sudo
access./etc/systemd/system
directory with a name of myapp.service
/etc/systemd/system/myapp.service
[Unit]
defines the description of the service, [Service]
defines how the service is executed and [Install]
tells the operating system when to run the application. For example[Unit]
Description=My Application As A Service
[Service]
User=myapp_user
Group=myapp_group
Type=simple
ExecStart= java -jar /home/ubuntu/myapp/myapp.jar -Xmx512m –Xms512m -XX:MaxNewSize=384m -XX:MaxPermSize=128m
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
/etc/systemd/system
directory.Type
can be set to simple
for most cases. This defines that the application will run immediately without forking any other processes. For a definition of the other options available here, check out the man pages for systemd.ExecStart
specifies the command that is used to run the application. Here, we specify the entire command line (including java
and any parameters) to run the application. This can be very useful as we can specify which version of Java to use here, so an application can be configured to run with any required JVM, and not only with the system's default JVM. Any JVM properties or application variables can be configured here.SuccessExitStatus
tells systemd that the application has closed cleanly in this situation..service
file has been created, we need to tell systemd that we have a new service. This is achieved by executing:sudo systemctl daemon-reload
sudo systemctl start myapp
sudo systemctl stop myapp
sudo systemctl status myapp
sudo systemctl enable myapp
[Service]
section of the file.Restart=on-failure
RestartSec=10s