3

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 ?

Steven Monday
  • 13,599
  • 4
  • 36
  • 45
Thibaut Barrère
  • 691
  • 1
  • 9
  • 17

3 Answers3

5

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.

Kyle Brandt
  • 83,619
  • 74
  • 305
  • 448
  • 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 '19 at 21:25
4

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.

LawrenceC
  • 1,202
  • 7
  • 14
1

https://help.ubuntu.com/community/UbuntuBootupHowto

nitins
  • 2,579
  • 15
  • 44
  • 68