Best Tools/Open Source Libs

How to run Java application as service on Linux

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:

  • System and service manager for Linux operating systems.
  • Systemctl to introspect and control the state of the systemd system and service manager.
  • systemd-analyze package to determine system boot-up performance statistics and retrieve other state and tracing information from the system and service manager.
Image – systemd Architecture

In the next section, we can take look at how to make Java application as Linux Daemon

#1.Create a new file on /etc/systemd with your service name

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).

Image – Daemon definition file

#2.Reload Linux Daemon

Use command systemctl daemon-reload to reload the service before we enable the newly added service

Image – Reload Daemon

#3.Enable newly added service

Enable the new service by using systemctl enable <service name> command.

Image – Enable service

#4.Start the service & check the status

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.

Image – Start the service

#5.Stop / Disable service

As the last step, if we want to stop the service, use systemctl stop <service name> command.

Image – Stop the service

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!

Summary
Article Name
How to run Java application as service on Linux
Description
In this post,we check out how to run Java application as service on Linux and also start automatically if and when system restarts.
Author
Publisher Name
Upnxtblog
Publisher Logo
Karthik

Allo! My name is Karthik,experienced IT professional.Upnxtblog covers key technology trends that impacts technology industry.This includes Cloud computing,Blockchain,Machine learning & AI,Best mobile apps, Best tools/open source libs etc.,I hope you would love it and you can be sure that each post is fantastic and will be worth your time.

Share
Published by
Karthik
Tags: linuxsystemd

Recent Posts

Navigating Volatility: Investing in Crypto Derivatives and Risk Management Strategies

The cryptocurrency market is famed for its volatility, presenting each opportunity and demanding situations for…

2 weeks ago

How Game Developers Use AI in Mobile Games in 2024?

Games since time immemorial have been winning at captivating the users and teleporting them onto…

3 weeks ago

The Impact of AI on Software Development

We are living within an innovation curve wherein cutting-edge technologies are making a hustle and…

3 weeks ago

AI Tools for Research Paper Writing: Learn What They Can Do

Whether it’s the healthcare industry or the automobile sector, artificial intelligence has left its impact…

1 month ago

Embracing Innovation: 5 Ways AI is Transforming the Landscape in 2024

Facts only- The big Artificial Intelligence push is unraveling in 2024. No, it wasn’t merely…

1 month ago

The Startup Guide to Acquiring Exceptional Developers

In the fiercely competitive world of Hire Developers for Startup, success hinges not just on…

2 months ago

This website uses cookies.