Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

I have a Java executable program that I can run by typing java -jar abc.jar in terminal. How can I run it as a service? I want to run it as a service like by typing service abc start.

share|improve this question
A more complete answer is here:… Basically, in Ubuntu you can create a script for /etc/init.d which can start/stop/restart your service. – Mr Ed Apr 16 '14 at 11:35

3 Answers 3

up vote 8 down vote accepted

Upstart scripts have to placed at /etc/init/, ending with .conf.

Basically they require 2 sessions: one to indicate when to start, and another with the command to exec.

The easiest script to start with your sample is:

# myprogram.conf
start on filesystem
exec /usr/bin/java -jar /path_to/program

Of course, created as root under /etc/init/myprogram.conf.

If your script requires more than one command line, use the script section:

# myprogram.conf
start on filesystem
    /usr/bin/java -jar /path_to/program
    echo "Another command"
end script

To enable bash completion for your service, add a symlink into /etc/init.d folder:

sudo ln -s /etc/init/myprogram.conf /etc/init.d/myprogram

Then try start and stop it:

sudo service myprogram start

Of course, if you read the upstart cookbook, you can create pre-start/post-start and pre-stop/post-stop commands to be executed.

And, additionally, I read you want to check if a process is running. Check this question and maybe use the pre-start section.

share|improve this answer

You need to create an upstart.

Upstart is (IMHO) a disaster compared to good ol' SysV init scripts. Upstart is FAR more effort with little upside to the added work. With that said, I suspect there will be a few upstart defenders out there that will take me to task for me stating the obvious ;-)

share|improve this answer
It's just a file in /etc/init/yourservice.conf with a line indicating when to start, and another to the exec command. Fedora uses upstart too. Additionally, even Debian is changing its starting schema to SystemD, which will be Ubuntu schema in the future. – Rael Gugelmin Cunha Apr 16 '14 at 11:52

I can give you some best alternative than that, that is using alias. Its rather easier than doing service abc start.

you can simply call it everytime when ever you want with abc. If you want to do it , then open your terminal and type as

gedit .bashrc

then at the end type a line as

alias abc=' ava -jar abc.jar '

Then save and close the file.

Then restart the bash with source ~/.bashrc from your terminal.

Now if you type abc in your terminal automatically it will access the jar file you have given.

share|improve this answer
Many thanks, this information is very useful. Actually my point is that I want to check if my process is running or not running easily and I want it to run on background. If I create an alias like you said, can I see the process name as "abc" in process list after typing "ps -A"? – mecek Sep 30 '13 at 14:50
If its running...then you can. – Raja Sep 30 '13 at 15:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.