LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-05-2011, 10:16 AM   #1
gw1500se
Member
 
Registered: Mar 2004
Distribution: Mandriva 2010.0
Posts: 250

Rep: Reputation: 31
shutdown via init.d problem


I am pulling my hair out trying to figure out why a script is not being executed during shutdown. I have a script in 'init.d' that works properly from command line. It also works fine at boot. My problem is that it does not execute at all on shutdown. I am using all the standard rc.d stuff for the script. Here are my LSB tags:
Code:
### BEGIN INIT INFO
# Provides: setwebpage
# Required-Start: $network httpd
# Required-Stop: $network httpd
# Default-Start: 5
# Default-Stop: 0 1 2 3 4 6
# Short-Description: upload web page redirects
# Description: Uploads either a web page redirect or show server down
### END INIT INFO
When I check the rc?.d directories, the appropriate links are there with the proper NN. This script has to FTP a couple of files to a remote server so the network is required and the script should be run very early in the shutdown process. However, the first thing the script does is send a message via 'logger' indicating it is executing with the 'start' or 'stop' parameter. The 'stop' message never shows up in the log thus I have to conclude that it simply is never executed and I have no idea why. Can someone help me with this problem? TIA.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 02-06-2011, 04:33 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: 988
Blog Entries: 4

Rep: Reputation: 254Reputation: 254Reputation: 254
Greetingz!

Well, it *sounds* like everything's in place....let's make sure there isn't a typo somewhere;

1) You mentioned you have links in the right /etc/rc*.d directories...symbolic or hard?
2) can you post the content of the script?
(if there's anything sensitive in it, feel free to redact it)
3) How are you doing your reboots/shutdowns?
If you're just "init 6"-ing the box, I don't think it walks the /etc/rc*.d tree. But using "shutdown -y now" should work.
 
Old 02-06-2011, 08:08 AM   #3
gw1500se
Member
 
Registered: Mar 2004
Distribution: Mandriva 2010.0
Posts: 250

Original Poster
Rep: Reputation: 31
Thanks for the reply and the help.
Quote:
Originally Posted by xeleema View Post
Greetingz!

Well, it *sounds* like everything's in place....let's make sure there isn't a typo somewhere;

1) You mentioned you have links in the right /etc/rc*.d directories...symbolic or hard?
Symbolic but the links were all generated with 'chkconfig add'.
Quote:
2) can you post the content of the script?
Code:
#!/bin/sh
#
# Startup script for setting up web redirect pages
# description: Uploads either a web page redirect or show server down page
#
#
### BEGIN INIT INFO
# Provides: setwebpage
# Required-Start: $network httpd
# Required-Stop: $network httpd
# Default-Start: 5
# Default-Stop: 0 1 2 3 4 6
# Short-Description: upload web page redirects
# Description: Uploads either a web page redirect or show server down page
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

# source network configuration
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 1

NAME=/usr/local/sbin/setwebpage.pl
RETVAL=0

start() {
    $NAME start
}

stop() {
    $NAME stop
}

# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        start
        ;;
    reload)
        start
        ;;
    condrestart)
        start
        ;;
    status)
        echo "setwebpage status is not applicable"
        RETVAL='1'
        ;;
    *)
        gprintf "Usage: %s {start|stop|restart|reload|condrestart|status}\n"
        exit 1
esac

exit $RETVAL
Quote:
(if there's anything sensitive in it, feel free to redact it)
3) How are you doing your reboots/shutdowns?
If you're just "init 6"-ing the box, I don't think it walks the /etc/rc*.d tree. But using "shutdown -y now" should work.
I use either 'shutdown -r now'.
 
Old 02-06-2011, 08:45 AM   #4
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: 988
Blog Entries: 4

Rep: Reputation: 254Reputation: 254Reputation: 254
Kewl!
Okay, it to this;
Code:
    stop)
        logger "Stop for setwebpage - Started"
        stop && logger "Stop for setwebpage - Finished"
        ;;
Then manually stop it. You should have two entries in your syslog. If you do, then run the following commands;
Code:
tail -f /var/log/messages &
shutdown -r now
That should show you the syslog while the server is going down.

If this DOESN'T work, the there's only three things left to check;

1) The /usr/local/sbin/setwebpage.pl script may be taking too long to stop.
2) There might be a problem in that setwebpage.pl script itself.
3) It may actually be working, but syslog may be stopped before this stop script is called.
 
Old 02-06-2011, 09:36 AM   #5
tommylovell
Member
 
Registered: Nov 2005
Distribution: Raspbian, Debian, Ubuntu
Posts: 380

Rep: Reputation: 103Reputation: 103
I don't know Mandriva. But...

If this is like Fedora/Redhat then you need a need to create a "lock file" at startup in order to have the KNNyyyyyy rc script driven at shutdown.

If you do a 'grep touch /etc/rc5.d/*' and it gives you a lot of hits that would confirm it, I think.

If so (and I'm assuming your init.d script is named 'setwebpage'), a cheap fix would be to change your start routine in /etc/rc.d/init.d/setwebpage (or /etc/init.d/setwebpage) to

Code:
start() {
    touch /var/lock/subsys/setwebpage
    $NAME start
}
and your stop routine to
Code:
stop() {
    /bin/rm -f /var/lock/subsys/setwebpage
    $NAME stop
}
You could make it a little more elegant by checking for the existence of the lock file with
[ -f /var/lock/subsys/setwebpage ] and conditionally start or stop based on the existence or absence of the lock file.

If you are curious, in Fedora there is a script, /etc/rc, that is executed when the runlevel changes. You're going from runlevel '5' to runlevel '0' or '6', so /etc/rc0.d/Kxxsetwebpage or /etc/rc6.d/Kxxsetwebpage will be executed unless you run afoul of the following line in /etc/rc in the "kill" section.
Quote:
[ -f /var/lock/subsys/$subsys ] || [ -f /var/lock/subsys/$subsys.init ] || continue
where $subsys is the name of your init.d shell script.

The complete 'kill' and 'start' routines from /etc/rc in Fedora. Mandriva may differ.
Code:
# First, run the KILL scripts.
for i in /etc/rc$runlevel.d/K* ; do

        # Check if the subsystem is already up.  #[ed. long standing typo... I think it should read 'down'] 
        subsys=${i#/etc/rc$runlevel.d/K??}
        [ -f /var/lock/subsys/$subsys ] || [ -f /var/lock/subsys/$subsys.init ] || continue
        check_runlevel "$i" || continue

        # Bring the subsystem down.
        [ -n "$UPSTART" ] && initctl emit --quiet stopping JOB=$subsys
        $i stop
        [ -n "$UPSTART" ] && initctl emit --quiet stopped JOB=$subsys
done

# Now run the START scripts.
for i in /etc/rc$runlevel.d/S* ; do

        # Check if the subsystem is already up.
        subsys=${i#/etc/rc$runlevel.d/S??}
        [ -f /var/lock/subsys/$subsys ] && continue
        [ -f /var/lock/subsys/$subsys.init ] && continue
        check_runlevel "$i" || continue
                    
        # If we're in confirmation mode, get user confirmation
        if [ "$do_confirm" = "yes" ]; then
                confirm $subsys
                rc=$?
                if [ "$rc" = "1" ]; then
                        continue
                elif [ "$rc" = "2" ]; then
                        do_confirm="no"
                fi
        fi

        update_boot_stage "$subsys"
        # Bring the subsystem up.
        [ -n "$UPSTART" ] && initctl emit --quiet starting JOB=$subsys
        if [ "$subsys" = "halt" -o "$subsys" = "reboot" ]; then
                export LC_ALL=C
                exec $i start
        fi
        $i start
        [ -n "$UPSTART" ] && initctl emit --quiet started JOB=$subsys
done
 
2 members found this post helpful.
Old 02-06-2011, 09:47 AM   #6
gw1500se
Member
 
Registered: Mar 2004
Distribution: Mandriva 2010.0
Posts: 250

Original Poster
Rep: Reputation: 31
xeleema: Thanks again. I'll give that a try but I have a couple of musings:

1) I wondered about the script taking too long but I doubt it since running it manually is only a couple of seconds. I am not convinced that the script is even executed during shutdown.
2) This seems unlikely since it works fine manually. I don't know what could be different during shutdown that would cause it to fail. I tried running the script with 'at' to make sure there was nothing in the console-less environment but it worked fine. Also the perl script has lots of logging in it and nothing every shows up during shutdown. I am pretty sure that script is never executed since I don't believe the init.d script is executed. Your suggestion may help prove that.
3) If I knew what it was, I would add syslog to my required headers but 'syslogd' is apparently not recognized there.

Last edited by gw1500se; 02-06-2011 at 09:49 AM.
 
Old 02-06-2011, 09:52 AM   #7
gw1500se
Member
 
Registered: Mar 2004
Distribution: Mandriva 2010.0
Posts: 250

Original Poster
Rep: Reputation: 31
tommylovell: Thanks. I was not aware of that and there does not seem to be anything in the documentation about. However, upon investigating there certainly are lock files there for all the services in init.d. I'll give that a try too.
 
Old 02-12-2011, 06:39 PM   #8
gw1500se
Member
 
Registered: Mar 2004
Distribution: Mandriva 2010.0
Posts: 250

Original Poster
Rep: Reputation: 31
tommylovell: You win the prize. The lock file was the correct diagnosis. As soon as I added it to my init.d script, the shutdown worked flawlessly. Thanks.
 
Old 02-12-2011, 06:41 PM   #9
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: 988
Blog Entries: 4

Rep: Reputation: 254Reputation: 254Reputation: 254
Sweet! Can you mark this thread as "[SOLVED]" (via "Thread Tools" at the top of the page)?
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between init 0 and shutdown -h now cheng0017 Linux - Newbie 3 03-28-2010 01:38 PM
Redhat Ent 3 AS init.d won't shutdown db ilerdl Red Hat 4 06-23-2009 08:45 AM
Shutdown problem : Usage: init PeterOnTheNet Slackware 12 03-03-2005 09:22 PM
Init 0 does not shutdown the server on its own samble Linux - General 5 11-10-2003 01:38 PM
Service Shutdown and Init Setup g_goblin Solaris / OpenSolaris 1 10-29-2003 03:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:01 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
Open Source Consulting | Domain Registration