Help - Search - Members - Calendar
Full Version: Config shutdown
Linuxhelp > Support > Technical Support
Yes of course I'm a newbie, taking a class at collage using Redhat 7.2 to learn with. As a final project I wnat to write a script that will run when
automaticly when you shut down - I've written the script o.k. but search as I might I cant figure out how to link it to the shutdown procedure, is there a way?
Well, you can place the script inside of /etc/init.d/ directory, and make sure that it follows pretty much in line with the other scripts that are located in that directory (being that it handels the "start" "stop" "restart" "reload" parameters). From there, you need to install links in the proper runlevel directorys. If you look in /etc you should see the directorys: rc0.d, rc1.d, rc2.d, rc3.d, rc4.d, rc5.d and rc6.d. Each of these directorys contains scripts that either start or stop different services depending on what runlevel the system is moving to. Two examples of links can be something like the following:

user@host:$ ls /etc/rc2.d
S90programX    K50programY

So lets break it down:


S/K: Controls wether the services is starting or stopping during this runlevel. <S> Start <K> Stop.
n: Controls what order the script is run with reference to the other scripts in the directory
Programname: What is being run

So, if I wanted to run dhcp on init 2 (Runlevel 2) then I first make the script that was able to handel the start, stop, restart, reload parameters, store this file in /etc/init.d (and make it executable), then I would create a link to that file:

ln -s /etc/init.d/dhcp /etc/rc2.d/S90dhcp

Now this script will run each time the computer hits runlevel two. Equally, you can make the script stop the service in runlevel 0 or 6. Here is a brief description on each runlevel:

0 Halt
1 Single-user mode
2 Not used (user-definable)
3 Full multi-user mode
4 Not used (user-definable)
5 Full multi-user mode (with an X-based login screen)
6 Reboot
Thank you very much for responding, you may have given me the key to my "A" from the class. From all of the reading I have done I was moving in the right direction but it didn't make sense to me as all of the directories seemed to have only to do with startup so even though I knew I was looking in the right areas I couldn't figure out where to put and where/how to link from.
hrmm, i should have been a teacher.

and to think, when i go back to college next month, I got to do Introduction to Unix smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2018 Invision Power Services, Inc.