Creating an Init Script in Ubuntu 14.04

Creating an Init Script in Ubuntu 14.04

In Ubuntu, you create init scripts using the SysV init system. Details are here. In this article, I will create a very simple script to start and stop Tomcat.

In this tutorial, our goal is to start and stop Tomcat as the user “joe”. First, we will create a script called tomcat in /etc/init.d folder.

The “Default-Start” field specifies the run levels in which the script will be run with the “start” argument. “Default-Stop” does the reverse. For example, when the machines shuts down and enters run level 1, the script will be run with the “stop” argument.

Make the script executable:

Always unit test the script by running it from the command line. For example:

If all goes well then register the script as an init script:

Reboot the machine and make sure that Tomcat has started.

Author Surjit Sidhu

Surjit SidhuSurjit is a student of IT, a freelance web designer/developer and a tech writer. He deals with both front-end and back-end stuff. Whenever he is not in front of an Internet-enabled device he is probably reading a book or traveling.

Leave a Reply

Be the First to Comment!

avatar

wpDiscuz