Scripts under rc0.d and rc6.d do not seem to run during shutdown.reboot
Linux - NewbieThis forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I am using RedHat 9 and have problems running scripts that should run during shutdown/reboot.
I placed a script under /etc/init.d/ ('my_script') and made a symbolic link (K40my_script)to it in /etc/rc0.d/ (for shutdown) and /etc/rc6.d/ (for rebooting).
However, when I shutdown/reboot I do not see (during shutdown/reboot on the screen within the list of scripts being run) that my scripts run.
During startup (boot), I do see (on the screen within the list of scripts running) that the script (symbolic link, 'S99my_script' under /etc/rc5.d/) runs.
Does anyone have an idea why my script does not run during shutdown/reboot although it exists as a symbolic link under rc0.d and rc6.d?
When you put a link in rcX.d, the first letter tells the system to either start (S) or kill (K) the process. If you have K for kill, then I'm not sure you would see anything happening.
Did you want your script to start or kill when re-booting or shutting-down?
The scripts aim to stop processes that are running. As such I think they should be 'K'. I also thought that all scripts in rc0.d and rc6.d which are shutdown and re-boot levels should be 'K'. Do you think they may need to be 'S'? What is the meaning of an 'S' script during shutdown (isn't shutdown when you want to kill (and not start) all processes?)
I thought that maybe the scripts do actually run (and I just do not 'see' them run on the console). But then:
a. I get a 'FAIL' on the screen when the system tries to shut down PPP0 (during shutdown) and that proves to me that my script is not running (it is a script that stops my internet cable connection). Had my script run, I expect PPP0 to be shut without failing.
b. If K20mysql exists under rc6.d and during re-boot I see on the screen that the mysql is running (stopping), why would I not see K40my_script run during re-boot (it is also under rc6.d)?
The reason RedHat does not kick off your K* rc shutdown scripts is because RedHat checks for a lock file for your script in /var/lock/subsys/<scriptname>
To fix this, simply add a line to your 'start' section, something like this:
Code:
touch /var/lock/subsys/<scriptname>
This will create that 0 byte file that rc is looking for when it executes shutdown.
Here is the actual snippet of the code from /etc/rc.d/rc that does this:
Code:
# First, run the KILL scripts.
for i in /etc/rc$runlevel.d/K* ; do
check_runlevel "$i" || continue
# Check if the subsystem is already up.
subsys=${i#/etc/rc$runlevel.d/K??}
[ -f /var/lock/subsys/$subsys -o -f /var/lock/subsys/$subsys.init ] \
|| continue
# Bring the subsystem down.
if egrep -q "(killproc |action )" $i ; then
$i stop
else
action $"Stopping $subsys: " $i stop
fi
done
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
Advertisement
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Click Here to receive a complimentary subscription courtesy of LQ.