Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

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.

share|improve this answer
add comment

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

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

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.