Systemd is a system manager and the new Linux init system. This guide shows how to start a Java application with the
Create Java Application User
For security purposes, the application should be run as an unprivileged user (i.e. not root). We will create a new user and group that will run the application service.
First, create a new
$ sudo groupadd -r jvmapp
Next, create a new jvmapp user. This user should be a member of the former created
jvmapp group, with a home directory of where the location of the application is (e.g.
/opt/application), and with a shell of
/bin/false (so nobody is able to log into the account)
$ sudo useradd -r -g jvmapp -s /bin/false -d /opt/application jvmapp
jvmapp user is set up.
Create a systemd Service File
As the user root, create a
application.service file in the
$ vi /etc/systemd/system/application.service
Write the following content inside the file.
[Unit] Description=Java Application Service After=network.target [Service] ExecStart=/path/to/java -jar /path/to/application.jar User=jvmapp Group=jvmapp [Install] WantedBy=multi-user.target
Start the application as a service
After saving the file, reload the systemd daemon so that it knows about the new service.
$ systemctl daemon-reload
Start the Application service by typing
$ systemctl start application
Show the status, if the service is started
$ systemctl status application
Now the service should start by each start of the system.