justlinux.com
Tue, 09-Feb-2010 16:04:14 GMT
internet.com
Forum: Registered Users: 73634, Online: 273
nhfs Here you can view your subscribed threads, work with private messages and edit your profile and preferences Registration is free! Calendar Find other members Frequently Asked Questions Search Home Home

Help File Library: Where Do I Put Startup Commands In Debian?


Written By: Craig McPherson

I've seen this question pop up a whole lot lately... most recently, twice in five minutes by two different people on the message board.

The question is "What's the Debian equivalent of rc.local" or "Where can I put startup commands in Debian?"

Here's a quick step-by-step guide to one way to do this:

  1. Execute this command to find your default runlevel:
    cat /etc/inittab | grep initdefault
    You should see a line like this:
    id:2:initdefault:
    That means 2 is your default runleve. This may also be 3, or rarely 4 or 5.
  2. Create your rc.local file like this (as root):
    touch /etc/init.d/rc.local
    chmod 774 /etc/init.d/rc.local
  3. Set it to be run at boot time by doing this:
    ln -s /etc/init.d/rc.local /etc/rcX.d/S99local
    Replace the X with your default runlevel from step one. For example, rc2.d.
  4. Edit your /etc/init.d/rc.local script.

End Notes

This'll cause your rc.local script to be run last during the bootup process (because of the 99). This is generally what you want to do, to make sure your network connection is up and all the basic services are started before your custom startup script runs.

If for some reason you have commands you need to run sometime eariler in the bootup process, you can create multiple scripts this way. It doesn't matter what you name them, just stick them in /etc/init.d, then symlink to them from /etc/rcX.d. Make sure the name of the symlink starts with a capital S, and is followed by a two-digit number: the lower the number, the sooner during bootup the script will be run. Don't run it too early or your filesystems might not even be mounted yet!

If you want your script to ALWAYS be run, no matter what runlevel you boot into, even in Single User Mode (runlevel 1), make your symlink in /etc/rcS.d instead of /etc/rcX.d.

Several nice folks have e-mailed me and reminded me about Debian's update-rc.d utility. If you want to delve less deeply into the innards of the SysV init system, you can replace step 3 above with the following command:
update-rc.d -f rc.local start 99 2 3 4 5

This assumes you want to run your script in runlevels 2, 3, 4, and 5. If you only want to run it in say, runlevel 3, remove the 2, 4, and 5. This also assumes you want to run it last (99) during the bootup process, use a value smaller than 99 if you want it run sooner. Don't forget the period at the end.


internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
internet.commerce
Be a Commerce Partner












The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers