Runlevel testing in init scripts

DJ Lucas dj_me at
Tue Sep 10 08:06:17 PDT 2002

Björn Lindberg wrote:
> I still haven't been able to figure out what you're actually trying to
> do here. :-) What kind of checking?

Firstly, thanks Richard and Björn.  Okay, here is the reasoning behind this.
The testing is to simply make the init script more inteligent and not
display anything in the start/stop cases if it is not supposed to be run.
Also, I've finally bothered to look at the rc script and found that the two
variables mentioned in the info for runlevel are in the rc script, just not
exported to the environment. So my previous two scripts are of no use if rc
is sourced in the script.  They were not created without learning so it was
not a complete waste of time for me. ;-) Anyhow, switching from runlevel 2
to runlevel 6, where I have not started the network, the network stop script
is run reguardless and displays the big failed message in it's own error in
logic because in switching to rl2,  I've already killed the network.  I had
wanted to include this checking in the killproc and loadproc functions as
opposed to making the individual scripts themselves more inteligent.  Say,
logically, and I know the syntax is incorect, using the situation above the
$PREVLEVEL variable would contain a value of 2 and $RUNLEVEL would contain a
value of 6.  so.....if exist /etc/rc.d/rc"$PREVLEVEL".d/K??"$0" then and
exit 0.  Unfortunately this would require an additional checking in restart
but that could be as simple as seting a constant of RSTRUE=TRUE in the
restart section of the script.

> The name of the script is available in the variable $0, eg:
> d95-bli at monty:~/tmp> cat
> #!/bin/bash
> echo $0
> d95-bli at monty:~/tmp> ./
> ./
> d95-bli at monty:~/tmp>
> Björn

Unsubscribe: send email to listar at
and put 'unsubscribe lfs-chat' in the subject header of the message

More information about the lfs-chat mailing list