LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices

Reply
 
LinkBack Search this Thread
Old 02-12-2009, 03:27 PM   #1
druidmatrix
LQ Newbie
 
Registered: Feb 2009
Posts: 13

Rep: Reputation: 0
Kill scripts not being executed upon reboot


Hello,

I have an application that absolutely needs the kill script to run on reboot/shutdown. I have the service added to chkconfig running at runlevels 3,4 and 5. I have the necessary S and K scripts (S is 99 and K is 01) in /etc/r3.d, rc4.d and rc5.d. I also have the K01 link in /etc/rc6.d.

When I issue a `reboot` from runlevel 3, I dont see any of the K scripts executing, although the S script does run at startup. I can tell this because the first line in the init.d script is to write a line to the application log file - "starting" for start and "stopping" for stop. I see the "starting" lines, but no "stopping" lines at all unless the script is run manually with a stop argument.

I am RHEL5 release 5.1 (Tikanga). Has anyone else come across similar issues? Perhaps one of the Guru's will be kind enough to take a look?

Thanks in advance.
 
Old 02-12-2009, 04:01 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,534
Blog Entries: 51

Rep: Reputation: 2603Reputation: 2603Reputation: 2603Reputation: 2603Reputation: 2603Reputation: 2603Reputation: 2603Reputation: 2603Reputation: 2603Reputation: 2603Reputation: 2603
What does this services initscript script look like?
 
Old 02-12-2009, 04:27 PM   #3
druidmatrix
LQ Newbie
 
Registered: Feb 2009
Posts: 13

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by unSpawn View Post
What does this services initscript script look like?
-bash-3.1# cat /etc/init.d/impgre
#!/bin/sh
# chkconfig: 345 99 01
# description: this script starts and stops the GRE tunnel mgr
#
IMPGRE_HOME=/prod/IM/apps/impgre

case "$1" in
'start')

. ${IMPGRE_HOME}/cfg/impgre.cfg
echo -n "Starting the Tunnel Manager..." >> ${LOG_DIR}/impgremgr.log
${IMPGREMGR}/bin/impgremgr -D
;;

'stop')
. ${IMPGRE_HOME}/cfg/impgre.cfg
echo -n "Shutting down the Tunnel Manager..." >> ${LOG_DIR}/impgremgr.log
if [ -e "${IMPGREMGR}/tmp/tun_mgr.pid" ]; then
kill -INT `cat ${IMPGREMGR}/tmp/tun_mgr.pid`
else
echo "Impgremgr does not appear to be running"
fi
while [ -e "${IMPGREMGR}/tmp/tun_mgr.pid" ] ; do
sleep 1
done
;;
 
Old 02-13-2009, 01:46 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,534
Blog Entries: 51

Rep: Reputation: 2603Reputation: 2603Reputation: 2603Reputation: 2603Reputation: 2603Reputation: 2603Reputation: 2603Reputation: 2603Reputation: 2603Reputation: 2603Reputation: 2603
This initscript doesn't adhere to standards: sourcing initscript configuration should be in /etc/sysconfig/${servicename}, it doesn't use the default reporting and kill routines, and the "case" statement isn't closed (unless you didn't bother to post the whole script). What I'd do is look at default initscripts in /etc/rc.d/init.d, copy one then make it fit this service. That way you will have less things to modify, meaning less chances for making errors. If it *then* still doesn't work it would be easier to modify the script (post your "new" script) and ensure it remains consistent with the rest.
 
Old 02-16-2009, 01:36 PM   #5
druidmatrix
LQ Newbie
 
Registered: Feb 2009
Posts: 13

Original Poster
Rep: Reputation: 0
UnSpawn,

You are absolutely right - it is not the complete script (although I think an esac would complete it) - the main thing I had tried to point out was the logging statements right at the beginning of the "start" and "stop" cases. I see both outputs in the log file if I do a manual /etc/init.d/impgre start|stop (no user environment needed). But I only see the "Starting.." statement when I do a reboot.

I am not sure what you meant by "default reporting and kill routines" - I am expecting a kill to come from the init.d script being run with "stop" by the OS during a change in runlevel. Are you saying that the application needs to be registered under /etc/services in order for the K scripts to run? In that case, why is it different for the corresponding S scripts? This bothers me....

Thanks in advance.
 
Old 02-16-2009, 02:11 PM   #6
druidmatrix
LQ Newbie
 
Registered: Feb 2009
Posts: 13

Original Poster
Rep: Reputation: 0
One other pertinent point I should have mentioned (in light of your above response) is that the application is not added to chkconfig - I am only using the /etc/init.d/rcX.d links to the /etc/init.d/scriptname. Shouldn't that be supported?
 
Old 02-16-2009, 05:36 PM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,534
Blog Entries: 51

Rep: Reputation: 2603Reputation: 2603Reputation: 2603Reputation: 2603Reputation: 2603Reputation: 2603Reputation: 2603Reputation: 2603Reputation: 2603Reputation: 2603Reputation: 2603
Quote:
Originally Posted by druidmatrix View Post
I am not sure what you meant by "default reporting and kill routines" (...) Are you saying that the application needs to be registered under /etc/services in order for the K scripts to run?
/etc/services has nothing to do with this, it's a simple, static port - servicename mapping "database" (think IANA). I mean the default routines as any initscript would use them (meaning sourced from /etc/rc.d/init.d/functions IIRC). Defaulting to available features means taking away chances for making mistakes (why invent the wheel?), and if those functions don't cover starting or stopping services properly, *then* you could expand your initscript: take a look at how for instance the sshd service implements stopping.


Quote:
Originally Posted by druidmatrix View Post
One other pertinent point I should have mentioned (in light of your above response) is that the application is not added to chkconfig - I am only using the /etc/init.d/rcX.d links to the /etc/init.d/scriptname. Shouldn't that be supported?
Well, the /etc/init.d/rcX.d links basically are what 'chkconfig' governs. If there's a proper kill link in rc6 then this service is covered.
 
Old 02-16-2009, 07:00 PM   #8
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 11,806

Rep: Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923
I just had a look at an old Centos server I have laying around unloved ...
Looks like it /etc/rc checks for a lock file for the "subsystem" on shutdown to see if the K??* needs to run.
Should be as simple as putting a touch for the lockfile in the start section of the script - as suggesed, just check any other (running) service script.
 
Old 02-17-2009, 07:35 PM   #9
druidmatrix
LQ Newbie
 
Registered: Feb 2009
Posts: 13

Original Poster
Rep: Reputation: 0
UnSwpawn and Syg - both of you are absolutely right. What is needed is the /var/lock/subsys/scriptname file. Now I ask, and I am not sure this is the correct forum, can anyone confirm if this is needed for other Unix systems as well? I haven't done this on Solaris, for instance, and don't think it is needed (I haven't actually tried it with this particular app to be honest).

But thank you once again for your help.
 
Old 02-17-2009, 08:03 PM   #10
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 11,806

Rep: Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923
Init scripts are the last place you would expect consistency.
And there isn't any - even with Linux they all do it differently (e.g. SuSE uses a different approach).
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Scripts under rc0.d and rc6.d do not seem to run during shutdown.reboot oferu Linux - Newbie 4 03-26-2008 10:34 AM
S or K in the shutdown/reboot scripts... deepugopi Linux - Server 6 11-13-2007 11:35 PM
RHEL3: init scripts aren't executed dabang Red Hat 2 01-04-2007 07:54 AM
Linux HA and writing scripts to kill process sceadu Programming 0 07-28-2005 03:27 AM
reboot does not kill sshd erif Slackware 6 05-12-2004 11:39 AM


All times are GMT -5. The time now is 06:49 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration