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 ?


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.

  • 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
  • 1
    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
  • I'm not sure "these days" upstart is part of Ubuntu. – Chris Nadovich Aug 29 at 21:25

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.

  • 1
    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
  • The skeleton file is present in my recent version of ubuntu, but upstart is not (systemd is). – Chris Nadovich Aug 29 at 21:28


  • The above link doesn't seem to be up to date with recent versions of Ubuntu – Chris Nadovich Aug 29 at 21:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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