Originally posted by: SystemAdmin
All:
I've seen several posts on various forums, groups and wikis that state that AIX startup/shutdown scripts can be run by placing a "K" or "S" prefixed script (or a symlink) in the appropriate /etc/rc.d/rcX.d folder e.g. /etc/rc.d/rc2.d/ .
I'll admit I'm a newbie to AIX, but I think I've investigated this enough to state that this is an partially invalid piece of advice --- at least with respect to shutdown.
I know that as a newbie, I should tread carefully here, and in fact, I'm secretly hoping that I'll be proven wrong, so that I can learn something new, but I think I've performed my due diligence here. I'm guessing (I don't really know this) that this advice (with respect to shutdown) may be valid in other flavors of UNIX/Linux, but not valid in AIX, at least 5.3L.
I've posted the full scripts at the bottom of my post, so that everyone can check my work here.
From my examination, here is how things really work:
The /etc/rc.d/rcX.d/ folders CAN be used for startup scripts. Near the end of the boot process, /etc/initab is processed. /etc/inittab contains the following:
l2:2:wait:/etc/rc.d/rc 2
l3:3:wait:/etc/rc.d/rc 3
l4:4:wait:/etc/rc.d/rc 4
l5:5:wait:/etc/rc.d/rc 5
l6:6:wait:/etc/rc.d/rc 6
l7:7:wait:/etc/rc.d/rc 7
l8:8:wait:/etc/rc.d/rc 8
l9:9:wait:/etc/rc.d/rc 9
Assuming we are running at the standard run-level of "2" /etc/rc.d/rc 2 is invoked. The rc script checks the parameter (2), validates the existance of the specific run-level folder (e.g. /etc/rc.d/rc2.d/), and then enumerates the "K" and "S" prefixed scripts.
Now here is the first suprising (at least to me) bit of info -- at boot time, both the K(kill)scripts and the S(Start) scripts are invoked! This actually could be a minor problem if the "K" scripts exists!
Now, because the "K" scripts are first executed, and then followed by the "S" scripts, of course, our "S" scripts "win out".
HOWEVER -- there is nothing that I can see that would allow the "K" scripts to be invoked on their own. If you invoke /etc/rc.d/rc, you are always going to end up with the startup scripts being run. (I imagine it would have made more sense if rc took "start" or "kill" as a second parameter.
I imagine one could write a rc.shutdown script that would infact invoke the "K" scripts, but it seems a waste -- might as well just reference them directly or link to them.
The only reason I can see that you might want to keep "K" scripts in the etc/rc.d/rcX.d/ folders is that one can supposedly run a command such as init 2 (or telinit 2) to change your run-level which is supposed to re-invoke inittab. (From my experiment, simply re-specifiying the same run-level does not re-invoke inittab).
(There could also be a clever script written to check the run-level, and then execute only the "K" scripts. But I haven't found that anywhere. Did i miss something?
So, I'll sit back and let someone else educate me now! (Which I will welcome!). But for now, it appears to me that /etc/rc.shutdown is where my shutdown scripts need to be referenced.
Dave
<hr />
(POST of /etc/rc.d/rc script follows):
#!/bin/ksh
-
IBM_PROLOG_BEGIN_TAG
-
This is an automatically generated prolog.
-
bos53J src/bos/etc/rc.d/rc.sh 1.3
-
Licensed Materials - Property of IBM
-
Restricted Materials of IBM
-
(C) COPYRIGHT International Business Machines Corp. 2000,2006
-
All Rights Reserved
-
US Government Users Restricted Rights - Use, duplication or
-
disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
-
IBM_PROLOG_END_TAG
#############################################################
-
file name: rc
-
purpose: run user-provided scripts in rc directories
#############################################################
#run level parameter
run_level=${1}
#check if valid run level was requested
case "$run_level"
in
01 ) echo "Invalid run level choice; levels 0 and 1 are reserved in AIX ";;
a-zA-Z ) echo "Please enter a run level from 2 to 9";;
esac
#check if run level directory exists
if then
#get a list of the "kill" scripts in this directory
k_list=$(ls /etc/rc.d/rc${run_level}.d | grep "^K" | sort -)
#get a list of the "start" scripts in this directory
s_list=$(ls /etc/rc.d/rc${run_level}.d | grep "^S" | sort -)
#execute "kill" scripts
if then
for item in ${k_list}
do
/etc/rc.d/rc${run_level}.d/${item} stop
done
fi
#execute "start" scripts
if then
for item in ${s_list}
do
/etc/rc.d/rc${run_level}.d/${item} start
done
fi
else
echo "Requested run level directory does not exist"
fi
exit 0
(END OF SCRIPT and POST!)
#AIX-Forum