2

How do I make Ubuntu Servers run services at boot time, in a specific order?

I have read a bit about Upstart, init.d and inittab, and I'm not sure what's the right approach for doing it.

Thanks,

Udi

Adam Matan
  • 13,194
  • 19
  • 55
  • 75

3 Answers3

3

Look into the command update-rc.d, which is the standard Debian/Ubuntu way to set up starting and halting of services. The file /etc/init.d/skeleton is also a quite nice template for making your own services quickly and with correct behaviour.

Morten Siebuhr
  • 639
  • 1
  • 6
  • 16
2

Aside from upstart (which I don't know much about), order is determined by a number in the rcX.d directory (where X is the run level).

Usually, in Ubuntu, normal use is runlevel 2. You put your script in /etc/init.d/ and make a symbolic link to /etc/rcX.d with the following syntax:

  • S to start or K to stop the service
  • A two digit number with the order of execution (the smaller, the sooner)
  • The name of the script

If your script is number42 do this:

$ sudo cp number42 /etc/init.d
$ sudo ln -s /etc/init.d/number42 /etc/rc2.d/S99number42

Stopping it will be the same but with a K and in runlevel 0 and 6.

sysv-rc-conf can help you visualize which scripts run on which runlevel.

sysv-rc-conf http://ubuntu-tweak.com/wp-content/uploads/2007/09/sysv-rc-conf.png

chmeee
  • 7,370
  • 3
  • 30
  • 43
0

You mention in a specific order, but if you mean you have multiple processes, and you need them to run in a specified order, but after all the other boot-time processes have started, you can take the easy way out and use /etc/rc.local.

Simply put all your commands in that file in the order you specify, it will be executed by /bin/sh after all other boot processes have started. Make sure that your process detaches, or append an & to the end of each line or your boot will hang!

The above solutions are more robust, this way is more quick-n-dirty.

Justin Ellison
  • 718
  • 5
  • 9