[SOLVED] Any ideas on how I can ensure that a service is stopped before RHEL is shutdown?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Any ideas on how I can ensure that a service is stopped before RHEL is shutdown?
I have a program that I don't think its being shutdown properly prior to RHEL being shutdown (with the shutdown -h now command).
I looked around and there is no log for the shutdown process, I looked in /var/logs/messages and see nothing.
Is there a work around to add a script to issue 'service <program> stop' when 'shutdown -h now' is executed?
Is there a log that shows all the shutdown messages to proves that the program is shutdown completely?
Generally, services running on the system are listed in the /etc/init.d folder have a link in the runlevel folders as well. If your system runs in the graphical interface (runlevel 5) then your services are started at bootup in /etc/rc.d/rc5.d/, if it's command-line only check rc3.d. In those folders, you'll see symbolic links to the init.d folder's services that are named with S and K. When you enter that runlevel (i.e. boot), the K services are killed and the S services are started in the order that they're numbered. Someone feel free to correct me if I'm not saying that quite right.
My recommendation is that you make sure that you have a K90MyProgram link in the rcx.d folders for your service. (Note: substitute a good number for the 90, that puts it in a reasonable place in your kill sequence, and of course change MyProgram to the name of the service that you're trying to shutdown with the system.)
I believe that the shutdown command is essentially calling init 0
Maybe that's not the direction your question was going...
If so, look in /etc/init.d for the startup program. Check the start and stop values they'll look like this.
# chkconfig: 2345 55 25
Note that it is and should be commented out. The fist number is the runlevel(s) it will run under, the second is the start value, third, stop value.
The higher the value the later it starts & stops. 2345 10 90 will run under runlevels 2, 3, 4 and 5. It will start very early in the boot process and stop very late.
If it's not a service, you can copy one of the files under /etc/init.d/ that closely matches your needs.
When you've got it, run
chkconfig --add <program>
Use this advice at your own risk. Strange things can happen if improperly executed.
If I execute 'service tsm01 stop' it works exactly like it should. Unfortunately, when I execute a 'shutdown -h', RHEL does not stop it clean, i.e. the way 'service tsm01 stop' would. Right now the work around is to having to issue the service stop command manually before a shutdown to keep the integrity of the program. This really sucks.
Here is the tsm01 script in init.d... I would change it in a heartbeat, but I'm not at all sure what it is to change. I would check the shutdown list, but I don't know where one is?
echo "Stopping $prog instance $instance ..."
if [[ -e $pidfile ]]
# make sure someone else didn't kill us already
running=`ps -ef | grep $prog | grep -w $progpid | grep -v grep`
if [[ -n $running ]]
#echo "executing cmd kill `cat $pidfile`"
kill `cat $pidfile`
while check_running; do \
echo "$prog instance $instance still running, will check after $SLEEP_INTERVAL seconds"
total_slept=`expr $total_slept + 1`
if [ "$total_slept" -gt "$MAX_SLEEP_TIME" ]; then \
echo "Unable to stop $prog instance $instance"
echo "$prog instance $instance stopped Successfully"
# remove the pid file so that we don't try to kill same pid again
if [[ $? != 0 ]]
echo "Process $prog instance $instance stopped, but unable to remove $pidfile"
echo "Be sure to remove $pidfile."
echo "$prog instance $instance is not running."
[ $rc -eq 0 ] && rm -f /var/lock/subsys/dsmserv
Sorry guys... I did find the K's... they are in rc0.d rc1.d rc6.d
So, whatever runlevel you specify for the program, there will be a S<StartPrioritynumber><Programname>. Whatever runlevel you did not specify, that runlevel will contain K<StopPrioritynumber><Programname>.
A running service must have a file in /var/lock/subsys, that matches the service name, to be cleanly stopped via the service function as part of the shutdown process. The program creates a file named “/var/lock/subsys/dsmserv”. This matches the task name (from a “ps –e” command) but not the “service” name of “tsm01”