I have a script that I would like to run as a service on my Ubuntu Server 11.04 headless box. That is, I want to have the correct files under /etc/init.d/ and to be able to control it via the service command.

Is there any guide available that will show me how to do this?


Unless you are using 15.04 or any later release (which uses systemd), you will probably be better off if you turn your script into an Upstart job, rather than follow the examples you'll find in /etc/init.d/ (which are System V-style init scripts, which Ubuntu and other distributions are moving away from).

The Upstart Cookbook has an enormous amount of information about how Upstart jobs work. Although I wouldn't describe it as a HOWTO, if you combine the information there with looking through the stock Ubuntu Upstart jobs in /etc/init/ you will start to get the picture.

I suggest starting with section 4 and 5 of the Cookbook, "Concepts and Terminology" and "Configuration"


Here is a very simple example how to create an upstart script: https://wiki.frugalware.org/index.php/Upstart_Job_HOWTO

UPDATE: above link is broken. Here is an example of a script:

description "My startup service"
author "You or someone else"
version "3.14"

pre-start script
    echo 'Starting my service ...'
end script

start on net-device-up
stop on runlevel [!2345]

console output


exec /path/to/your/custom/script

Adapt as necessary.

You should place the script in /etc/init/yourfilename.conf

Then reload the configuration with:

sudo initctl reload-configuration

And if all is OK, you should be able to start it with:

sudo start yourfilename

protected by heemayl Aug 4 '15 at 10:35

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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