I am trying to understand how run levels work. I understand the meaning of the 7 run levels and I understand that they were usually configured by /etc/inittab, which used to call /etc/init.d/rc, which itself called the various scripts to configure the different run levels and how they should behave.

Right now I am on an Ubuntu Server machine (12.04) and I see that the inittab file is not used anymore and that instead, scripts are found in the /etc/init directory.

Now suppose that I want to execute a script at boot time (for example to launch an application). Usually I would do this editing the /etc/init.d/rc.local file.

And here comes my question: if I edit this file, will this script run for every run level?

If I want the script to work only at run level 5 for example, should I put this script into the /etc/rc5.d/ folder instead? Or is there another way to do this?


In Ubuntu, this is called Upstart. I suggest you read the Cookbook, it discusses how to create scripts to run at a specific (pseudo) runlevel.

What you're refering to, is the "System V" init system. The idea is to have things started concurrently. I suggest you take a look at the instance functionality of Upstart.

  • Thanks for your answer! Are there other distros that still use run levels though? In this case, how would this work? – user1301428 Aug 27 '13 at 12:23
  • @user1301428 well, that's almost a philosophical question. the *BSDs still adhere firmly to the "System", as they're more direct descendants of the UNIX from AT&T. Fedora still uses init-rc quite extensively, and I still make init scripts. Ubuntu tries to streamline the boot process, to make booting quicker, etc. hence, Upstart. – polemon Aug 27 '13 at 12:25
  • Ok I see. Both with System and Upstart though, is editing the rc.local file still the best way to do this? – user1301428 Aug 27 '13 at 12:28
  • @user1301428 I can't say that. It depends on what you want to do. if it is some server you're managing, probably not. If it's logging or "householding", probably yes. If it is something periodically happening, maybe crontab is the better solution. Identifying what's best for you, is yours to decide. – polemon Aug 27 '13 at 12:31
  • askubuntu.com/questions/9853/… <-- that's probably relevant, to you. rc.local is actually ran by Upstart once in the boot process (I'm not exactly sure when, though). – polemon Aug 27 '13 at 12:42

Ok so this is what I found out:

The latest Ubuntu versions make use of upstart (as @polemon correctly pointed out), which uses specific config files in the /etc/init directory to configure the run level at which a script should run. Upstart puts upstart job files in the /etc/init folder and normal init scripts in /etc/init.d and in the various /etc/rc*.d folders and is actually able to run both of them.

Systems not using upstart only use /etc/init.d and /etc/rc*.d. In this case, runlevels are set adding a symlink to the script in the appropriate /etc/rc*.d folder.

Also, apparently rc.local runs the scripts at multiuser runlevel.

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.