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

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?

share|improve this question

2 Answers 2

up vote 10 down vote accepted

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"

share|improve this answer

Here is a very simple example how to create an upstart script:

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
share|improve this answer . Link is broken. –  Jijoy May 31 at 15:48

protected by heemayl Aug 4 at 10:35

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

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.