Linux Logo
In this post, we check out how to run Java application as service on Linux and also start automatically if and when the system restarts.
Before we move on to the article, let us understand what is systemd .It is part of Linux kernel that provides the System and Service Manager to bootstrap user space and manages user processes that include startup shell scripts like pm-utils, inetd, acpid, syslog, watchdog, cron and atd. systemd’s core components include the following:
In the next section, we can take look at how to make Java application as Linux Daemon
sudo vi /etc/systemd/system/springbootapp.service
[Unit] Description=SpringBoot Service [Service] User=nobody WorkingDirectory=/home/demo1 ExecStart=/usr/bin/java -Xmx256m -jar /home/demo1/spring-boot-rest-postgresql-0.0.1-SNAPSHOT.jar --server.port=8081 SuccessExitStatus=143 TimeoutStopSec=10 Restart=on-failure RestartSec=5 [Install] WantedBy=multi-user.target
Modify Description, User, and ExecStart fields based on your application needs.WantedBy=multi-user.target
denotes that this service will only be started when the system boots up to this target (a non-graphical multi-user environment).
Use command systemctl daemon-reload
to reload the service before we enable the newly added service
Enable the new service by using systemctl enable <service name>
command.
Next step is to start the service by systemctl start <service name>
command and you can check the status by using systemctl status <service name>
command.
As the last step, if we want to stop the service, use systemctl stop <service name>
command.
If you want to disable the service, use systemctl disable <service name>
command.
Congrats! today we have learned how to Java application as Linux daemon service. If you re-look at the steps, it’s the same for any kind of application.
There are also other options like System V init script but Systemd is the preferred option as of now.
Like this post? Don’t forget to share it!
As a business, you need to make a lot of important decisions to keep things…
If you are software programming in the era of ‘digital first’, APIs (Application Programming Interfaces)…
Smartwatches have changed the way we organize our daily lives. They not only keep us…
You’ve been targeting people, developing interesting content and managing marketing campaigns. However, it appears that…
The world of wearable technology has been evolving at a rapid pace, with one of…
As we wrap up 2024, it’s time to reflect on the incredible journey we’ve had…
This website uses cookies.