will@dontUthink.com
Revision History | ||
---|---|---|
Revision v1 | Unknown by Tom | Revised by: wdt |
The HTML version | ||
Revision v2.0 | 18 February 2001 | Revised by: teh |
The SGML version | ||
Revision v2.1 | 5 January 2002 | Revised by: rl |
Fixed update-rc.d example |
If you haven't tinkered with ps yet, now's the time.
$ ps axf |
$ man ps |
$ ps afx PID TTY STAT TIME COMMAND 5790 ? S 1:41 /usr/sbin/xinetd 25445 ? S 0:00 \_ in.telnetd: wdt 25446 pts/0 S 0:00 \_ -tcsh 25878 pts/0 T 0:00 \_ vi runlevels-intro.wml 26045 pts/0 R 0:00 \_ ps afx |
Below, I run the ps program again, but ask for a LONG listing via ps afxl:
$ ps afxl F UID PID PPID STAT TTY TIME COMMAND 100 0 1 0 S ? 0:17 init [2] 140 0 5790 1 S ? 1:41 /usr/sbin/xinetd 100 101 25445 5790 S ? 0:00 \_ in.telnetd: wdt 100 1000 25446 25445 S pts/0 0:00 \_ -tcsh 000 1000 25878 25446 T pts/0 0:01 \_ vi runlevels.wml 000 1000 26072 25446 R pts/0 0:00 \_ ps axfl |
All processes are spawned by init, or by processes whose ancestor is init. Period!
Great. So how the heck does init know what to do?
id:2:initdefault: |
si::sysinit:/etc/init.d/rcS |
l2:2:wait:/etc/init.d/rc 2 |
Anyhow, what the /etc/init.d/rc script does is look in
/etc/rc[runlevel-digit].d/* /etc/rc2.d/* |
1:2345:respawn:/sbin/getty 38400 tty1 2:23:respawn:/sbin/getty 38400 tty2 3:23:respawn:/sbin/getty 38400 tty3 4:23:respawn:/sbin/getty 38400 tty4 5:23:respawn:/sbin/getty 38400 tty5 6:23:respawn:/sbin/getty 38400 tty6 |
How do you find out which runlevel you're in right now? This one's easy. Try this:
$ /etc/runlevel S 2 |
# telinit 4 # telinit S # telinit 2 |
Very simple. Just telinit (as root) which runlevel to switch to, and you're off!
Sorry, I can't answer that... But you can.
Remember the /etc/inittab section that showed what to do on each runlevel?
l0:0:wait:/etc/init.d/rc 0 l1:1:wait:/etc/init.d/rc 1 l2:2:wait:/etc/init.d/rc 2 l3:3:wait:/etc/init.d/rc 3 l4:4:wait:/etc/init.d/rc 4 l5:5:wait:/etc/init.d/rc 5 l6:6:wait:/etc/init.d/rc 6 |
So we hafta check into that script to see what the argument does.
If you look at the /etc/init.d/rc script, you'll find portions that look something like this:
# Is there an rc directory for this new runlevel? if [ -d /etc/rc$runlevel.d ] ... for i in /etc/rc$runlevel.d/K[0-9][0-9]* ... for i in /etc/rc$runlevel.d/S* |
/etc/rc3.d/K20postgresql stop |
/etc/rc3.d/S60sshd start |
BUT! There are certain preset runlevels that have important meanings:
There are Debian ways of munging the directory of scripts that the /etc/init.d/rc script calls upon.
In order to affect a runlevel, you need to create a script that does some work.
# cd /etc/init.d # cp skeleton my_sample_script |
# cd /etc/rc4.d $ ls -F S10sysklogd@ S20gpm@ S20postgresql@ S50wu-ftpd@ S99rmnologin@ S12kerneld@ S20inetd@ S20ssh@ S60sshd@ S19bind@ S20logoutd@ S20xinetd@ S89atd@ S20cipe@ S20makedev@ S22ntpdate@ S89cron@ S20exim@ S20mysql@ S23ntp@ S91apache@ |
Here's how you set up your script to START as sequence #70 and STOP as sequence #50 for runlevel 4:
# update-rc.d my_sample_script start 70 4 . stop 50 4 . |
# update-rc.d my_sample_script start 70 2 3 4 5 . stop 50 2 3 4 5 . |
![]() | I'll do this later |
When you decide to REMOVE your script (or any other service) from a runlevel, do like so:
# cd /etc/init.d # mv my_sample_script my_sample_script.DISABLED # update-rc.d my_sample_script remove |
Don't stop here! Learn more by trying these:
$ man init $ man inittab $ man ps $ man update-rc.d http://packages.debian.org/procps http://www.eGroups.com/files/newbieDoc |