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.
Make sure you're on 14.04. Ubuntu 16.04 (and above) uses systemd, not Upstart.
A Upstart script is a script file placed at
/etc/init/ and ending in
It requires 2 sections: one to indicate when to start, and another with the command to execute.
The easiest script to start with your sample is:
# myprogram.conf start on filesystem exec /usr/bin/java -jar /path_to/program
Created as root under
If your script requires more than one command line, use the
script section instead of the
# myprogram.conf start on filesystem script /usr/bin/java -jar /path_to/program echo "Another command" end script
To enable bash completion for your service, add a symlink into
sudo ln -s /etc/init/myprogram.conf /etc/init.d/myprogram
Then try start and stop it:
sudo service myprogram start
According the upstart cookbook, you can create
post-stop commands to be executed.
Additionally, I read you want to check if a process is running. Check this question and maybe use the
You need to create an upstart. http://upstart.ubuntu.com/getting-started.html
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 ;-)