Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking for good resources to learn more about how to write/debug/maintain init.d scripts on Ubuntu.

Do you have any links or books to recommend ?

share|improve this question

These days init is actually being replaced by upstart in Ubuntu server. So what you probably want to do if you are writing these scripts is to try to write upstart ones instead of init. Here is a Getting Started Guide for upstart in Ubuntu.

share|improve this answer
I was really wondering about what to do with upstart: on one hand, I'd like to go forward, on the other hand all the tools I use come with some version of an init.d script... What are your thoughts on this ? – Thibaut Barrère Nov 22 '10 at 14:57
Well CentOS/RH are still using init so if you are packaging for both that you are going to have to learn both.. For the most part you can just look at the basic ones that are already there and just modify them... – Kyle Brandt Nov 22 '10 at 15:13
And looks like for RHEL 7 you may have to learn systemd. – mattdm Nov 22 '10 at 18:24
Some other concerns with upstart that might make you want to avoid it: 1) you can't get script output on stdout of the terminal invoking an initctl command, you have to tail log files, and 2) initctl always returns exit code 0, which can be a pain to deal with if you're trying to automate start/stop/restart with scripts. – overthink Nov 23 '12 at 14:30

This seemed pretty good. You also want to learn as much about bash as you can.

In the /etc/init.d directory, there's a skeleton file. You can use that as the basis for writing your own init script.

Remember that everything in the specific runlevel directory, /etc/rc0.d, /etc/rc1.d and so forth are symbolic links (ln /etc/init.d/myscript /etc/rc2.d/S50myscript -s, for example.) to scripts in /etc/init.d.

The first letter of the link, S or K, means to execute it when entering the runlevel (S), or leaving the runlevel (K). The two digits after that letter determine the order init calls it when that runlevel is entered.

Debugging is accomplished through liberal use of the echo command so you know what the script it doing, and thorough testing.

share|improve this answer
While you can write init and Upstart scripts in Bash, it's usually done using Bourne (sh) since it starts up and runs faster. – Dennis Williamson Nov 22 '10 at 15:19

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.