LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-20-2006, 06:41 AM   #1
vikasumit
Member
 
Registered: Apr 2006
Location: Delhi, India
Distribution: Fedore , CentOs, Debian
Posts: 121

Rep: Reputation: 15
Smile shutdown script for linux


HI,

anyone please let me know what is the name and path of shutdown script for Linux and in specific to CentOS (Fedore, RHL) linux

thanks
 
Old 05-20-2006, 08:05 AM   #2
Brian1
LQ Guru
 
Registered: Jan 2003
Location: Seymour, Indiana
Distribution: Distribution: RHEL 5 with Pieces of this and that. Kernel 2.6.23.1, KDE 3.5.8 and KDE 4.0 beta, Plu
Posts: 5,700

Rep: Reputation: 65
the shutdown command is loacted in /sbin/shutdown. As far as what exactly does it I am not exactly sure as script to script goes. I have not seen any flow chart on the subject. But this is the basics of it.

Many shutdown and startup items reside in /etc/rc.d/init.d. Those scripts are softlinks to filenames in all the runlevels like /etc/rc0.d - /etc/rc6.d. Each one of these have softlinks of the scripts in /etc/rc.d/init.d execpt for the beginning part of the name. They either have a S or K plus two digit number from 01 -99. S for start and K for kill. The order is defined by the two digit number. Now each runlevel in Redhat type distros work like this. When you boot up fisrt it goes into runlevel 1 which is single user mode. Then lets jump to runlevel 3. It is multiuser plus networking. It will start any scripts in there with an S and if any are running already with a K it will kill them. Now jump to runlevel 5 it is multiuser, networking, plus X server. Now on shutdown it runs into runlevel 6 and will kill any scripts that were running from previous runlevel. So if the script_one is running and K**script_one exist in runlevel 6 and you enter runlevel 6 then it will stop it. Now if you go in and look at each of these scripts in /etc/rc.d/init.d then you will see sections like start stop restart in them. These sections are used with the S K values and also you can use the command ' service <service_name> start ' or ' service <service_name> restart '. Service is a redhat distro command. All of this is part of stuff called sysinit. Read up on that for more info.

Now what does much of this calling in Redhat distros like what Centos is based on is /etc/rc.sysinit. It does all the calling to start up many other scripts like searching for hardware, starting scripts. Even those scripts may start other scripts. A complex setup but one can following the steps by looking at each script in order. Also there are a couple other scripts for strtup like /etc/rc which should not really be altered unless for sure. Then if you need to start some scripts or commands of your own the they can go into /etc/rc.local.

I know this is very broad explantion but should give you more ideas on your search.

Brian1

Last edited by Brian1; 05-20-2006 at 08:08 AM.
 
Old 05-20-2006, 08:22 AM   #3
vikasumit
Member
 
Registered: Apr 2006
Location: Delhi, India
Distribution: Fedore , CentOs, Debian
Posts: 121

Original Poster
Rep: Reputation: 15
Hi Brain1,

I check my rc6.d folder and found symbolic links their, so if I make a file (shellscript or perl script) to run few commands, when will these scripts be called,
does they get called (automatically) at time of boot up or user login or Shutdown and/or Restart etc..

And can you explain what these numbers are (1-6)

thanks
 
Old 05-20-2006, 10:17 AM   #4
Brian1
LQ Guru
 
Registered: Jan 2003
Location: Seymour, Indiana
Distribution: Distribution: RHEL 5 with Pieces of this and that. Kernel 2.6.23.1, KDE 3.5.8 and KDE 4.0 beta, Plu
Posts: 5,700

Rep: Reputation: 65
Depends on when you want them to run. K01 runs before K02. So if you want name it K01scriptone.

Quick search on google pointed to two pretty good links.
http://www.redhat.com/docs/manuals/l...down-init.html
http://www.comptechdoc.org/os/linux/...unscripts.html

You can use the command ' init 3 ' to goto runlevel 3.

I have used one of the existing scripts in /etc/rc.d/init.d and used one of the simpliest ones. Copied and renamed to a new name. Then modified by adding things I want to do on start in the start section same goes for the stop section. Then link to the proper runlevels.

Brian1
 
Old 05-21-2006, 11:46 PM   #5
vikasumit
Member
 
Registered: Apr 2006
Location: Delhi, India
Distribution: Fedore , CentOs, Debian
Posts: 121

Original Poster
Rep: Reputation: 15
Hi,

Thanks for the Link ... Just to confirm to run a script at time of shutdown , I put it in run level 0 and 6 both right
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Gentoo Shutdown Script Adam A Flynn Linux - Software 4 05-15-2006 07:12 AM
script at the shutdown dominant SUSE / openSUSE 4 10-15-2005 07:43 AM
shutdown script acidjuice Slackware 3 04-09-2005 05:19 PM
Shutdown script Hexane Mandriva 7 01-28-2005 01:36 AM
shutdown script Zolan Linux - Newbie 2 10-16-2004 09:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration