Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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.

If you need help constructing a script, I'd help you with that, just add a comment.

share|improve this answer
    
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
up vote 1 down vote accepted

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.

share|improve this answer

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.