LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-21-2009, 09:50 PM   #1
ToddAndMargo
Member
 
Registered: Feb 2009
Posts: 38

Rep: Reputation: 15
Why does my shutdown script not get called?


Hi All,

OS: CentOS 5.3 (RHEL 5.3 clone)

I am not having any luck getting my shutdown script to run. All of my scripts work correctly from the command line. Would someone tell me what I am doing wrong?

The shutdown script is called /etc/rc.d/init.d/local-shutdown:
Code:
#!/bin/sh
# /etc/rc.d/init.d/local-shutdown
# chkconfig: - 99 01
# description: custom shutdown script

/bin/logger -p user.notice -t local-shutdown " rc.local.shutdown has been invoked"

# Make sure rc.local.shutdown link exists:
if [ ! -h /etc/rc.d/rc.local.shutdown ]; then
   ln -s /etc/rc.d/init.d/local-shutdown /etc/rc.d/rc.local.shutdown
fi

# See what your environment is
date >> /tmp/local-shutdown.env.txt
env  >> /tmp/local-shutdown.env.txt
echo "" >> /tmp/local-shutdown.env.txt
echo "" >> /tmp/local-shutdown.env.txt
My find:

Code:
# find /etc/rc.d -iname \*local-shutdown\* -exec ls -al {} \;
lrwxrwxrwx 1 root root 24 Aug 21 13:04 /etc/rc.d/rc1.d/K01local-shutdown -> ../init.d/local-shutdown
lrwxrwxrwx 1 root root 24 Aug 21 13:04 /etc/rc.d/rc4.d/K01local-shutdown -> ../init.d/local-shutdown
lrwxrwxrwx 1 root root 24 Aug 21 13:04 /etc/rc.d/rc3.d/K01local-shutdown -> ../init.d/local-shutdown
lrwxrwxrwx 1 root root 24 Aug 21 13:04 /etc/rc.d/rc2.d/K01local-shutdown -> ../init.d/local-shutdown
-rwxr-xr-x 1 root root 1614 Aug 21 18:43 /etc/rc.d/init.d/local-shutdown
lrwxrwxrwx 1 root root 24 Aug 21 13:04 /etc/rc.d/rc6.d/K01local-shutdown -> ../init.d/local-shutdown
lrwxrwxrwx 1 root root 24 Aug 21 13:04 /etc/rc.d/rc5.d/K01local-shutdown -> ../init.d/local-shutdown
lrwxrwxrwx 1 root root 24 Aug 21 13:04 /etc/rc.d/rc0.d/K01local-shutdown -> ../init.d/local-shutdown
I get nothing in my /var/log/messages; I do not get the rc.local.shutdown link created; I do not get a file called /tmp/local-shutdown.env.txt. Nothing!

[rant]Editorial comment: AAAAAAHHHHHHHHH!!!![/rant]

What in the world am I doing wrong?

Many thanks,
-T
 
Old 08-22-2009, 01:27 AM   #2
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 987
Blog Entries: 4

Rep: Reputation: 252Reputation: 252Reputation: 252
Adding A Service

Greetingz!

Luckily, the object of your irritation is a quick fix. You have the script in init.d (which is a great first step), however you need to "link" it to a run level (in this case, probably rc6 and rc0 (zero)).

The utility needed for this in RedHat is "chkconfig", check the man page, but you're probably looking for something like "chkconfig --levels 06 rc.local-shutdown on".

For non-RedHat based Linux distributions, or other UNIX platforms in general, it's typically as simple as adding a symbolic link in /etc/rc6.d and /etc/rc0.d. However, in Solaris 10, you can really get involved with adding services with their Service Management Facility (SMF).

Hope this helps!

Last edited by xeleema; 08-22-2009 at 01:29 AM. Reason: Added "Other Linux Distro" information.
 
Old 08-22-2009, 02:18 AM   #3
ToddAndMargo
Member
 
Registered: Feb 2009
Posts: 38

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by xeleema View Post
Greetingz!

Luckily, the object of your irritation is a quick fix. You have the script in init.d (which is a great first step), however you need to "link" it to a run level (in this case, probably rc6 and rc0 (zero)).

The utility needed for this in RedHat is "chkconfig", check the man page, but you're probably looking for something like "chkconfig --levels 06 rc.local-shutdown on".

For non-RedHat based Linux distributions, or other UNIX platforms in general, it's typically as simple as adding a symbolic link in /etc/rc6.d and /etc/rc0.d. However, in Solaris 10, you can really get involved with adding services with their Service Management Facility (SMF).

Hope this helps!
I used it. What is wrong with my links?
My find:

Code:

# find /etc/rc.d -iname \*local-shutdown\* -exec ls -al {} \;
lrwxrwxrwx 1 root root 24 Aug 21 13:04 /etc/rc.d/rc1.d/K01local-shutdown -> ../init.d/local-shutdown
lrwxrwxrwx 1 root root 24 Aug 21 13:04 /etc/rc.d/rc4.d/K01local-shutdown -> ../init.d/local-shutdown
lrwxrwxrwx 1 root root 24 Aug 21 13:04 /etc/rc.d/rc3.d/K01local-shutdown -> ../init.d/local-shutdown
lrwxrwxrwx 1 root root 24 Aug 21 13:04 /etc/rc.d/rc2.d/K01local-shutdown -> ../init.d/local-shutdown
-rwxr-xr-x 1 root root 1614 Aug 21 18:43 /etc/rc.d/init.d/local-shutdown
lrwxrwxrwx 1 root root 24 Aug 21 13:04 /etc/rc.d/rc6.d/K01local-shutdown -> ../init.d/local-shutdown
lrwxrwxrwx 1 root root 24 Aug 21 13:04 /etc/rc.d/rc5.d/K01local-shutdown -> ../init.d/local-shutdown
lrwxrwxrwx 1 root root 24 Aug 21 13:04 /etc/rc.d/rc0.d/K01local-shutdown -> ../init.d/local-shutdown
 
Old 08-22-2009, 04:21 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by ToddAndMargo View Post
All of my scripts work correctly from the command line.
This problem is puzzling so time to dig more deeply. Can you post a "screen-scrape" of a terminal session showing exactly what you did and the evidence for "work correctly"?
 
Old 08-22-2009, 12:21 PM   #5
ToddAndMargo
Member
 
Registered: Feb 2009
Posts: 38

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by catkin View Post
This problem is puzzling so time to dig more deeply. Can you post a "screen-scrape" of a terminal session showing exactly what you did and the evidence for "work correctly"?
I don't know what a "screen-scrape" is, so will this do?

change to /etc/rc.d
Code:
[root@rn1 rc.d]# cd /etc/rc.d
look for link called rc.local.shutdown
Code:
# ls -al rc.local*
-rwxr-xr-x 1 root root 2895 Apr  2 09:54 rc.local
-rwxr-xr-x 1 root root  220 Jun 23  2003 rc.local.orig
rc.local.shutdown not found

run /etc/rc.d/rc0.d/K01local-shutdown
Code:
# /etc/rc.d/rc0.d/K01local-shutdown
Starting local-shutdown:
the "Starting ..." echo works. Note that I started it from one of my rcX.d links and not from init.d. So my rcX.d links are working.

relook for link:
Code:
# ls -al rc.local*
-rwxr-xr-x 1 root root 2895 Apr  2 09:54 rc.local
-rwxr-xr-x 1 root root  220 Jun 23  2003 rc.local.orig
lrwxrwxrwx 1 root root   31 Aug 22 10:12 rc.local.shutdown -> /etc/rc.d/init.d/local-shutdown
And now link exists (I will erase it shortly)

Now check if logger posted in messages:
Code:
# date
Sat Aug 22 10:15:08 PDT 2009
# grep -i local-shutdown /var/log/messages
Aug 22 10:12:25 rn1 local-shutdown:  rc.local.shutdown has been invoked
This is why I think everything works fine from the command line.

This is driving me nuts! It has to be one of those stupid mistakes that is so blatantly right under my nose I can not see it!

Thank you for looking over my code.
-T
 
Old 08-22-2009, 01:00 PM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Thanks T, that's beautifully clear.

Can I presume from the # prompt that you ran those tests as root?

As you say, the tests show that the symlink /etc/rc.d/rc0.d/K01local-shutdown can be used to run the script.

So let's focus on why the shutdown procedure isn't doing so ...

Do you have other K<nn>* symlinks in /etc/rc.d/rc0.d/ directory to other scripts that are evidenced to run at shutdown (no stone unturned)?

There's some distro-specific stuff about /etc/rc.d/rc0.d/ and /etc/rc0.d/ but I think systems using /etc/rc.d/rc[S0-6].d/ directories have directory symlinks set up ensure they can be treated as /etc/rc[S0-6].d/ and still work.

Is the 01 in your K01local-shutdown symlinks the numbers 0 and 1 or is one-or-more a letter O or l?

If your /tmp is cleared during shutdown/boot then can you change the output file for the commands after "# See what your environment is" to a permanent location?

In case there's any problem with /bin/logger during shutdown (there shouldn't be) can you put something like this before the /bin/logger command?
Code:
echo "$@" >> <a permanent location>/local-shutdown.env.txt
 
Old 08-22-2009, 03:18 PM   #7
ToddAndMargo
Member
 
Registered: Feb 2009
Posts: 38

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by catkin View Post
Can I presume from the # prompt that you ran those tests as root?
Yes, "#" is my root's prompt

Quote:
Do you have other K<nn>* symlinks in /etc/rc.d/rc0.d/ directory to other scripts that are evidenced to run at shutdown (no stone unturned)?
Yes, they all run, except mine

Quote:
Is the 01 in your K01local-shutdown symlinks the numbers 0 and 1 or is one-or-more a letter O or l?
The symlinks are created by the "chkconfig -add local-shutdown" command.
But, I checked anyway. They are real zero's and one's. I also tried switching to K13 from K01. It made no difference.

Quote:
If your /tmp is cleared during shutdown/boot then can you change the output file for the commands after "# See what your environment is" to a permanent location?
My /tmp directory is cleaned by age. I think it is set to a week or some such. If I write anything to it, it would still be there for a long while

Quote:
In case there's any problem with /bin/logger during shutdown (there shouldn't be) can you put something like this before the /bin/logger command?
Code:
echo "$@" >> <a permanent location>/local-shutdown.env.txt
/tmp does not get erased. I am sure of that.

The "huge" overwhelming symptom is that none of the debugging statements I have added to the script get called. The link does not get created, the logger statement does not happen, and the "env + echo" lines do not happen. This means that the script itself is not being called. And that baffles the h--- out of me!

Thank you for looking over my stuff.
-T
 
Old 08-22-2009, 04:32 PM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by ToddAndMargo View Post
The "huge" overwhelming symptom is that none of the debugging statements I have added to the script get called. The link does not get created, the logger statement does not happen, and the "env + echo" lines do not happen. This means that the script itself is not being called. And that baffles the h--- out of me!
I fully agree with your analysis Thank you for trying my suggestions even though you must have thought some of them futile.

One possibility is that the script that runs the boot scripts via the /etc/rc.d/rc[S0-6].d/ symlinks is "clever" about K* scripts.

I'm on ubuntu so details vary but I think that script on your system is /etc/rc.d/rc. If not, look around for the rc script somewhere related. Symlinks might make it accessible as /etc/init.d/rc.

My rc script contains this comment
Code:
                # If there is a stop script in the previous level
                # and _no_ start script there, we don't
                # have to re-stop the service.
The one thing you are doing that is unusual is having K01local-shutdown symlinks in the /etc/rc.d/rc[1-5].d directories. You could try removing them, leaving the symlinks only in the /etc/rc.d/rc[06].d directories as is conventional.
 
Old 08-22-2009, 05:09 PM   #9
ToddAndMargo
Member
 
Registered: Feb 2009
Posts: 38

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by catkin View Post
The one thing you are doing that is unusual is having K01local-shutdown symlinks in the /etc/rc.d/rc[1-5].d directories. You could try removing them, leaving the symlinks only in the /etc/rc.d/rc[06].d directories as is conventional.
chkconfig puts them in all seven, like it or not.
Code:
# find /etc/rc.d -iname \*local-shutdown\* -exec ls -al {} \;
lrwxrwxrwx 1 root root 24 Aug 21 13:04 /etc/rc.d/rc1.d/K01local-shutdown -> ../init.d/local-shutdown
lrwxrwxrwx 1 root root 24 Aug 21 13:04 /etc/rc.d/rc4.d/K01local-shutdown -> ../init.d/local-shutdown
lrwxrwxrwx 1 root root 24 Aug 21 13:04 /etc/rc.d/rc3.d/K01local-shutdown -> ../init.d/local-shutdown
lrwxrwxrwx 1 root root 24 Aug 21 13:04 /etc/rc.d/rc2.d/K01local-shutdown -> ../init.d/local-shutdown
-rwxr-xr-x 1 root root 1614 Aug 21 18:43 /etc/rc.d/init.d/local-shutdown
lrwxrwxrwx 1 root root 24 Aug 21 13:04 /etc/rc.d/rc6.d/K01local-shutdown -> ../init.d/local-shutdown
lrwxrwxrwx 1 root root 24 Aug 21 13:04 /etc/rc.d/rc5.d/K01local-shutdown -> ../init.d/local-shutdown
lrwxrwxrwx 1 root root 24 Aug 21 13:04 /etc/rc.d/rc0.d/K01local-shutdown -> ../init.d/local-shutdown
 
Old 08-23-2009, 12:48 AM   #10
ToddAndMargo
Member
 
Registered: Feb 2009
Posts: 38

Original Poster
Rep: Reputation: 15
Hi All,

I figured it out. I will post solution
tomorrow after I get some sleep.

-T
 
Old 08-23-2009, 10:34 PM   #11
ToddAndMargo
Member
 
Registered: Feb 2009
Posts: 38

Original Poster
Rep: Reputation: 15
[Solved] Why does my shutdown script not get called?

Todd wrote:
> Hi All,
>
> I am running CentOS 5.3 (RHJEL 5.3 clone). I am not having any luck
> getting a
> shutdown script to run. All of my scripts work correctly from the
> command line.
> Would someone tell me what I am doing wrong?
>

Figured it out. This ticket is actually a duplicate of
http://www.linuxquestions.org/questi...reboot-439249/

As LQ stats in the above posting:

Quote:
The reason RedHat does not kick off your K* rc shutdown
scripts is because RedHat checks for a lock file for your
script in /var/lock/subsys/<scriptname>
This was my goof.
My shutdown script (/etc/rc.d/init.d/a-local-shutdown)
now contains:

Code:
if [ "$1" = "start" ]; then
   lockfile=/var/lock/subsys/a-local-shutdown
   touch $lockfile
   /bin/logger -p user.notice -t a-local-shutdown \
   " rc.shutdown touched $lockfile"
   exit 0
fi
What a pain in the neck this was to figure out! I was
googling on "rc.local shutdown" and did not find the
above until I switch to "rc.shutdown red hat".

Please note that for everyone that ever wanted Red Hat
to do an /etc/rc.d/rc.shutdown, you now have one.
(My script creates a link to itself in /etc/rc.d
called "rc.shutdown".)

My thanks to everyone on this an other forums who
helped me on this. My final a-local-shutdown script follows.

-T

~~~~~~~~ /etc/rc.d/init.d/a-local-shutdown ~~~~~~~~~
Code:
#!/bin/sh
# /etc/rc.d/init.d/a-local-shutdown
#
# Similar to rc.local only run at shutdown (rc0/1/6.d)
#
#
# chkconfig: 35 99 01
# description: custom shutdown script
# lockfile: /var/lock/subsys/a-local-shutdown
#
# Note: RedHat checks for a lock file for your script in
#       /var/lock/subsys/<scriptname> or it won't run your
#       K* scripts.  You will find a "touch" command below under "start
#       to take care of this
#
#       On the above config command:
#
#       $1 run levels for start links (35 = rc3.d and rc5.d)
#       $2 start sequence  (14 = S14xxxx in the run levels listed in $1)
#       $3 stop seqence    (94 = K94xxxx in all rcX.d's) 
#       Sequences all (S & K) start from 00 (K is not a "down counter")
#          
#       install run levels with the following command:
#            /sbin/chkconfig --add a-local-shutdown
#
#       remove run levels with the following command (sometime necessary):
#            /sbin/chkconfig --del a-local-shutdown
#
#       list with
#            /sbin/chkconfig --list a-local-shutdown   or
#            find /etc/rc.d -iname \*a-local-shutdown\* -print   or
#            find /etc/rc.d -iname \*a-local-shutdown\* -exec ls -al {} \;
#
#
############################################################################
# >>>> Do not place any custom code until the comment bar says you can <<<<#
############################################################################

echo -n $"Starting local-shutdown: "; echo

# Make sure rc.local.shutdown link exists:
if [ ! -h /etc/rc.d/rc.shutdown ]; then
   ln -s /etc/rc.d/init.d/a-local-shutdown /etc/rc.d/rc.shutdown
fi


# Take care of start house keeping
if [ "$1" = "start" ]; then
   lockfile=/var/lock/subsys/a-local-shutdown
   touch $lockfile
   /bin/logger -p user.notice -t a-local-shutdown " rc.shutdown touched $lockfile"
   exit 0
fi

# Make sure this script was called correctly
if [ "$1" != "stop" ]; then
   echo $"Usage: $0 {start|stop}"
   exit 2
fi

# Make a note in /var/log/messages that this script has been called:
/bin/logger -p user.notice -t local-shutdown " rc.local.shutdown has been invoked"


###################################################
# >>>> Place your custom code below this line <<<<#
###################################################


# Shutdown Virtual Machines:
/home/linuxutil/VM-Utils stop VB-WinXP
/home/linuxutil/VM-Utils stop VB-WinXP2
/home/linuxutil/VM-Utils stop VB-KUbuntu
/home/linuxutil/VM-Utils stop VB-Vista
/home/linuxutil/VM-Utils stop VB-W7
/home/linuxutil/VM-Utils stop VB-W7beta


exit 0

Last edited by ToddAndMargo; 08-23-2009 at 11:11 PM. Reason: change title to "Solved"
 
1 members found this post helpful.
  


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
Expect Script not getting called in the Cron Job athreyavc Programming 3 11-10-2008 06:35 AM
how to pass a variable from a called script back to the calling script steven.c.banks Linux - General 2 05-05-2008 02:00 PM
can expect be called from within a bash script? johnpaulodonnell Programming 4 06-21-2007 09:42 AM
Running a script called INSTALL joshd1982 Linux - Newbie 3 01-29-2006 05:44 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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