Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tool for creating a Java daemon service on Linux [closed]

What is the best way to create a java application that can be run using ‘service’ on Linux? I was going to use the JSW available here, but cannot use the licence on that (licence is either GPL or it costs money as far as I can tell). I’d need an apache style licence.

I’m using maven to build, so it would be great if it was possible to create the service using a maven plugin, but any other suggestions would be great.

I've seen Apache Commons Daemon, is there a maven plugin for this? Documentation seems sparse, so a working example of this would be good...

Thanks

like image 946
Lehane Avatar asked Aug 21 '09 10:08

Lehane


People also ask

What is JSVC in Linux?

Jsvc is a set of libraries and applications that facilitates running Java applications on Linux, UNIX, and similar operating systems. Using Jsvc with Red Hat JBoss Web Server 3 allows Tomcat to switch identities. Using Jsvc, Tomcat can perform root-level operations and then revert to a non-privileged user.

What kind of file must you have to run a Java application on a Linux server?

Create a new file on /etc/systemd with your service name. 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).


1 Answers

Services on Linux are just shell scripts which start background processes. Have a look in /etc/init.d - you can open the files in a text editor. All you need is a bash script which responds to the parameters start and stop in an appropriate way (eg. start will start your service and record the process ID in a known location, stop will kill the process with the PID from the file you created), and then place it in /etc/init.d.

Have a look at Init Scripts and An introduction to services, runlevels, and rc.d scripts

like image 80
robertc Avatar answered Oct 07 '22 19:10

robertc