LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-17-2009, 11:36 AM   #1
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
Question first file which is executed when we reboot or shutdown Linux server


Hi All,

I am using RHEL 5.2. I wanted to know which file is executed at first when we shutdown or reboot Linux machine.

Actually, I have made a small script to start/stop an application.

To start it I can put start script into /etc/rc.d/rc.local

BUT I do not know where to put the stop script, so that it executes just in the starting of reboot or shutdown process.

Any idea, I have tried using K* scripts in /etc/rc0.d/ and /etc/rc6.d/ BUT I am looking for other options.
 
Old 08-17-2009, 12:16 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by vikas027 View Post
I have tried using K* scripts in /etc/rc0.d/ and /etc/rc6.d/ BUT I am looking for other options.
Maybe explain what your script is all about and why symlinking in /etc/rc0.d/ and /etc/rc6.d/ won't do?
 
Old 08-17-2009, 12:41 PM   #3
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Original Poster
Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by unSpawn View Post
Maybe explain what your script is all about and why symlinking in /etc/rc0.d/ and /etc/rc6.d/ won't do?
Hi Unspawn,

Yes, symlinking scripts should work BUT I was following this url. Here, it is written
Quote:
# ln -s /etc/init.d/dbora /etc/rc.d/rc0.d/K01dbora
# ln -s /etc/init.d/dbora /etc/rc.d/rc3.d/S99dbora
# ln -s /etc/init.d/dbora /etc/rc.d/rc5.d/S99dbora

The commands themselves work, I can see the links created, but my Oracle instance never seems to startup or shutdown properly.
Thus, I was trying it to start/stop Oracle at startup/shutdown by two ways:-
1) Through chkconfig which eventually makes S* and K* are soft links only.
I have also posted this link in "Linux General" forum.
2) Also, I was looking for other way round like to put a script when machines is just about to go off. I am sure there must be a way.

Learning is my motive . I want to learn it both ways, through chkconfig method as well as put a script/command in a system file which executes just in the starting of reboot or shutdown process.
 
Old 08-17-2009, 01:09 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
That makes this thread half crosspost and half not. Wrt symlinks SysV init works like that so if you've got problems with your init scripts I suggest you fix those first before trying to find workarounds that conflict with doing things the RHEL way.
 
Old 08-17-2009, 01:20 PM   #5
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Original Poster
Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by unSpawn View Post
That makes this thread half crosspost and half not. Wrt symlinks SysV init works like that so if you've got problems with your init scripts I suggest you fix those first before trying to find workarounds that conflict with doing things the RHEL way.
No, I do not have problem with any of my /etc/rc*.d/S* or /etc/rc*.d/K* scripts. These are working perfectly. Please have a look on my other post
http://www.linuxquestions.org/questi...init.d-748056/

But, still just for sake of knowledge I looking for something similar to /etc/rc.d/rc.local for reboot & shutdown.

Last edited by vikas027; 08-17-2009 at 03:39 PM. Reason: Just adding few more lines
 
Old 08-17-2009, 04:09 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by vikas027 View Post
But, still just for sake of knowledge I looking for something similar to /etc/rc.d/rc.local for reboot & shutdown.
OK. What application does 'shutdown' send a signal to on shutdown? Which configuration file does that other process use by default to handle runlevel changes? Would it be possible to add another line that could drive a process on entering runlevel 6?
 
Old 08-18-2009, 12:23 AM   #7
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Original Poster
Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by unSpawn View Post
OK. What application does 'shutdown' send a signal to on shutdown? Which configuration file does that other process use by default to handle runlevel changes? Would it be possible to add another line that could drive a process on entering runlevel 6?
hey, so many questions.
I did not knew my query would drive so many questions in turn !
 
Old 08-19-2009, 01:45 PM   #8
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Original Poster
Rep: Reputation: 107Reputation: 107
Anybody can please help me out to find the first script (if exists) in shutdown or reboot process. I have googled a lot but could not find anything.

Pls Help !!
 
Old 08-19-2009, 01:54 PM   #9
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
What application does 'shutdown' send a signal to on shutdown?
init of course.


Which configuration file does that other process use by default to handle runlevel changes?
/etc/inittab.


Would it be possible to add another line that could drive a process on entering runlevel 6?
Sure, why not?
 
Old 08-19-2009, 10:06 PM   #10
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Original Poster
Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by unSpawn View Post
What application does 'shutdown' send a signal to on shutdown?
init of course.


Which configuration file does that other process use by default to handle runlevel changes?
/etc/inittab.


Would it be possible to add another line that could drive a process on entering runlevel 6?
Sure, why not?
Thanks a ton unSpawn. I willl try it and get back to you. Sorry, this did not clicked on my mind. Will try it and update you with the results.
 
Old 08-20-2009, 06:18 AM   #11
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by vikas027 View Post
this did not clicked on my mind. Will try it and update you with the results.
True, but it does make me wonder how you can have a RHCE and be a "linux administrator" without knowing the most basic of basics (or how to find out for for yourself for that matter)...
 
Old 08-21-2009, 09:25 AM   #12
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Original Poster
Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by unSpawn View Post
True, but it does make me wonder how you can have a RHCE and be a "linux administrator" without knowing the most basic of basics (or how to find out for for yourself for that matter)...

It is my fault. I did not read your questions properly. I should have been more attentive to them.
 
Old 08-21-2009, 09:43 AM   #13
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
NP, happens to me too sometimes. Anyway, did you figure out how to make this work?
 
Old 08-22-2009, 06:14 AM   #14
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Original Poster
Rep: Reputation: 107Reputation: 107
Thumbs up

Quote:
Originally Posted by unSpawn View Post
NP, happens to me too sometimes. Anyway, did you figure out how to make this work?
Thanks unSpawn,

Well I got some good learning too reviewing /etc/inittab. I must admit, I did not paid required attention this file needed. Rather, till now I did not felt the need.

This worked out for me. I can modify the below lines of /etc/rc.d/rc

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
as here

Code:
# First, run the KILL scripts.
for i in /etc/rc$runlevel.d/K* ; do
        check_runlevel "$i" || continue

if [ $runlevel -eq 0 ] || [ $runlevel -eq 6 ]; 
then 
my script or my commands
fi

        # 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
I believe this should work. Thanks a ton for your patience and time.

Last edited by vikas027; 08-31-2009 at 12:50 PM. Reason: Added a space after $runlevel
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shutdown and Reboot Linux System via php script ramasubbu1984 Linux - Newbie 7 03-24-2009 09:09 AM
Kill scripts not being executed upon reboot druidmatrix Red Hat 9 02-17-2009 08:03 PM
Why do I loose Linux when I shutdown or reboot ? wertaylors Linux - General 4 04-06-2007 02:52 AM
Create and file system without reboot server richardchancs Linux - Enterprise 6 09-27-2006 01:33 PM
How does one shutdown and reboot linux from within a program? prometheus7817 Linux - General 2 08-27-2003 06:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:49 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