LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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!

Notices


Reply
  Search this Thread
Old 04-17-2013, 11:15 AM   #1
DavidDiepUSC
Member
 
Registered: Jan 2008
Posts: 58

Rep: Reputation: 0
Any ideas on how I can ensure that a service is stopped before RHEL is shutdown?


Hi everyone,

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?

Thanks for all your suggestions!
 
Old 04-17-2013, 01:13 PM   #2
DaPh00z
LQ Newbie
 
Registered: May 2011
Posts: 6

Rep: Reputation: Disabled
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...

Last edited by DaPh00z; 04-17-2013 at 01:18 PM.
 
Old 04-17-2013, 01:14 PM   #3
MPH426
LQ Newbie
 
Registered: Feb 2013
Posts: 17

Rep: Reputation: Disabled
Can you verify that it is a service?

chkconfig --list |grep <program>

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.
 
Old 04-17-2013, 01:26 PM   #4
DaPh00z
LQ Newbie
 
Registered: May 2011
Posts: 6

Rep: Reputation: Disabled
Some other threads that may be enlightening:

http://www.linuxquestions.org/questi...roblem-941806/

http://www.linuxquestions.org/questi...topped-879128/
 
Old 04-17-2013, 02:10 PM   #5
DavidDiepUSC
Member
 
Registered: Jan 2008
Posts: 58

Original Poster
Rep: Reputation: 0
Hi everyone,

Thank you very much for taking the time for these suggestions.

It is a service:

Code:
[root@TSM01 ~]# chkconfig --list tsm01
tsm01           0:off   1:off   2:on    3:on    4:on    5:on    6:off
The startup program does not have runlevels specified... it was added with

Code:
chkconfig --level 5 tsm01 on
Code:
#!/bin/bash
#
#
# chkconfig: - 90 10
# processname: dsmserv
# pidfile: /var/run/dsmserv_instancename.pid
Under /etc/rc.d/rc2.d, rc3.d, rc4.d, rc5.d I see the program:

Code:
S90tsm01
I do not see a K service at all... could this be the reason?
 
Old 04-17-2013, 02:17 PM   #6
DavidDiepUSC
Member
 
Registered: Jan 2008
Posts: 58

Original Poster
Rep: Reputation: 0
Just as a note...

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.
 
Old 04-17-2013, 02:24 PM   #7
DavidDiepUSC
Member
 
Registered: Jan 2008
Posts: 58

Original Poster
Rep: Reputation: 0
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?

Code:
stop() {
        echo  "Stopping $prog instance $instance ..."
        if [[ -e $pidfile ]]
        then
           # make sure someone else didn't kill us already
           progpid=`cat $pidfile`
           running=`ps -ef | grep $prog | grep -w $progpid | grep -v grep`
           if [[ -n $running ]]
           then
              #echo "executing cmd kill `cat $pidfile`"
              kill `cat $pidfile`

              total_slept=0
              while check_running; do \
                  echo  "$prog instance $instance still running, will check after $SLEEP_INTERVAL seconds"
                  sleep $SLEEP_INTERVAL
                  total_slept=`expr $total_slept + 1`

                  if [ "$total_slept" -gt "$MAX_SLEEP_TIME" ]; then \
                      break
                  fi
              done

              if  check_running
              then
                echo "Unable to stop $prog instance $instance"
                exit 1
              else
                echo "$prog instance $instance stopped Successfully"
              fi
           fi
           # remove the pid file so that we don't try to kill same pid again
           rm $pidfile
           if [[ $? != 0 ]]
           then
              echo "Process $prog instance $instance stopped, but unable to remove $pidfile"
              echo "Be sure to remove $pidfile."
              exit 1
           fi
        else
           echo "$prog instance $instance is not running."
        fi
        rc=$?
        echo
        [ $rc -eq 0 ] && rm -f /var/lock/subsys/dsmserv
        return $rc
}
 
Old 04-17-2013, 02:49 PM   #8
DavidDiepUSC
Member
 
Registered: Jan 2008
Posts: 58

Original Poster
Rep: Reputation: 0
Sorry guys... I did find the K's... they are in rc0.d rc1.d rc6.d

Code:
K10tsm01
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>.
 
Old 04-18-2013, 01:56 PM   #9
DavidDiepUSC
Member
 
Registered: Jan 2008
Posts: 58

Original Poster
Rep: Reputation: 0
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”
 
  


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
RHEL service shutdown problem Ren McCourtey Linux - Server 12 04-30-2012 06:46 PM
make shutdown wait until service is stopped bbrib Linux - General 4 05-16-2011 01:50 AM
Cron service and oracle service stopped unexpectedly. Can't restart oracle. camron Linux - Newbie 6 06-10-2010 07:00 PM
Shutdown timer, any ideas? sir_shunt SUSE / openSUSE 10 06-04-2008 12:20 AM
system reboots when i shutdown -h now. any ideas why? nass Slackware 11 04-27-2006 09:14 AM


All times are GMT -5. The time now is 08:00 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration