Friday, September 20, 2013

Running a JAR as a service using upstart

It is very simple to run JAR file as a daemon in latest version of linux using upstart script.Instead of creating a script in /etc/init.d, as with System-V init, you create a .conf file in /etc/init folder. Then upstart takes care of running it as a service.

This example for a 'sample' service for a sample.jar located in /usr/local/ folder( you can put jar anywhere in system, but always use absolute path)

Create a sample.conf file in /etc/init in following syntax


description "sample service" 
author "Jinesh" 

start on runlevel [3] 
stop on shutdown 

expect fork 

script 
      java -jar /usr/local/sample.jar
      emit sample_running 
end script 

Then you can start service using

service sample start

and stop using

service sample stop

No comments:

Post a Comment