LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 04-22-2013, 01:20 PM   #1
PeterSteele
Member
 
Registered: Jun 2012
Posts: 264

Rep: Reputation: Disabled
How can I ensure a shutdown handler is run before killall is run?


We have a process that we want to make sure is shutdown cleanly when a system is rebooted. I assume I can control this with a run-level 6 script K script, which would get launched with a "stop" argument when a system shutdown is initiated.

My process is configured to trap a kill -2 and shut itself down cleanly when this signal is received. So I tried creating a simple K script that does a kill -2 on my process. From my logs I can see that the signal handler starts, but the process dies shortly after that before it has completed its shutdown logic.

Is the system /etc/init.d/killall script running at the same time as the K scripts and stomping on my shutdown handler before I has a chance to complete? How can I ensure that my shutdown handler completes before killall is run? The killall script is not a K script, rather it is a run-level 6 S script, so I don't know what its sequence is respect to the K scripts.
 
Old 04-22-2013, 03:00 PM   #2
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
A K script wont run. Change it to an S and make sure the number is lower than the number on the Skillall in rc6.d directory
 
Old 04-22-2013, 03:50 PM   #3
PeterSteele
Member
 
Registered: Jun 2012
Posts: 264

Original Poster
Rep: Reputation: Disabled
Well, killall is defined as S00, so do I make mine S01 or rename killall to S01 and make mine S00?

When *should* I use K scripts anyway? There are lots defined for run-level 6.
 
Old 04-22-2013, 05:21 PM   #4
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
basically there will be a run level script in each of the rc.d directories. If it begins with K it will not run and if it begins S it will run. Its just a flag.
 
Old 04-22-2013, 06:25 PM   #5
PeterSteele
Member
 
Registered: Jun 2012
Posts: 264

Original Poster
Rep: Reputation: Disabled
I'm a bit confused, according to the documentation the K and S links behave as follows:

Quote:
The name of each symbolic link begins with either a K or an S. The K links are processes that are killed on that runlevel, while those beginning with an S are started.

The init command first stops all of the K symbolic links in the directory by issuing the /etc/rc.d/init.d/<command> stop command, where <command> is the process to be killed. It then starts all of the S symbolic links by issuing /etc/rc.d/init.d/<command> start.
So I'd think that if I had some service that I wanted to be stopped on shutdown (run level 6), then I'd put in a "stop" handler for that service and create a K link for it in /etc/rc6.d. On shutdown, the system will effectively do a

service myserv stop

At least that's how I interpret this documentation. I suppose I could also create a service and create an S link for it in /etc/rc6.d, but in this case I'd need to supply a "start" handler for it. On entering run level 6, the system will process my S link and do a

service myserv start

You are suggesting though that the K scripts aren't run at all?
 
Old 04-22-2013, 06:49 PM   #6
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
Your interpretation is actually correct, but I just simplified it to make it easy to understand. However, there are some things that go beyond just the basic S and K lettering. There are many more factors that come into play that are read. I would recommend using the /etc/init.d/ directory, create your own init script following the proper headings and then use the chkconfig program to build the correct scripts for it.


http://coreymaynard.com/blog/creatin...ipt-on-fedora/


If that is more than what you are trying to accomplish I would suggest just forking off the existing killall script.

http://magazine.redhat.com/2008/06/0...fy-and-master/
 
Old 04-22-2013, 07:23 PM   #7
PeterSteele
Member
 
Registered: Jun 2012
Posts: 264

Original Poster
Rep: Reputation: Disabled
I've already created my init.d script as per the usual specs. It has a start option that launches a particular process and is configured to launch on run-levels 2-5. The problem is that on shutdown I want the process that was launched by the init.d script on system start-up to be cleanly shutdown when the system is rebooted. The logs show that my process starts its orderly shutdown, and then it is killed before can be complete its tasks. I'm assuming this is done by killall, but I had thought that the K scripts would be allowed to complete before the run-level 6 S scripts (of which killall is one) are run.

How can I make sure my run-level 6 K script completes before killall is run?
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to stop fork_bomb script run by user without using killall command sanjay87 Linux - Server 1 05-26-2012 09:43 AM
How to run fsck during a shutdown sequence, or how to run one-time init scripts? bgoodr Debian 5 11-28-2010 03:08 PM
killall esd before game. run esd after game. missing gnome sounds. fakie_flip Linux - Games 3 09-30-2006 03:47 AM
killall X - this is not the proper shutdown mechanism, is it?? e-regular Linux - Newbie 4 09-10-2003 09:42 AM
Killall fails at shutdown/reboot. JMC Linux - General 6 07-22-2002 06:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat

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