Operating System - Linux
1753523 Members
11148 Online
108795 Solutions
New Discussion юеВ

Re: Redhat chkconfig script: does the 'stop' ever run?

 
SOLVED
Go to solution
LBertoglio
Advisor

Redhat chkconfig script: does the 'stop' ever run?

Hi all.
It seems that the "stop" part of some scripts listed in chkconf on my redhat AS 4.4 are never executed (but some are).
To show this, i created a test script, /etc/init.d/leo :
#!/bin/bash
# chkconfig: 345 99 01
# description: leonardo test
# source function library
. /etc/init.d/functions
case "$1" in
start)
echo -n "starting leonardo"
echo "$(date): $1" >/tmp/leo_start
;;
stop)
echo -n "stopping leonardo"
echo "$(date): $1" >/tmp/leo_stop
;;
*)
echo -n "others leonardo"
echo "$(date): $1" >/tmp/leo_others
exit 1
esac
exit 0
#########
Then I did: chmod 755, chown root:root,
chkconfig --add leo.
ll /etc/rc?.d/*leo*
.../etc/rc6.d/K01leonardo -> ../init.d/leonardo
.../etc/rc5.d/S99leonardo -> ../init.d/leonardo
.../etc/rc4.d/S99leonardo -> ../init.d/leonardo
.../etc/rc3.d/S99leonardo -> ../init.d/leonardo
.../etc/rc1.d/K01leonardo -> ../init.d/leonardo
.../etc/rc0.d/K01leonardo -> ../init.d/leonardo
Also 'chkconfig --list leonardo' give the expected output.
This script works fine when is executed from the command line with start|stop|SmthingElse parameters.
But after a reboot of the server, I just can find a /tmp/leo_start file, and a "starting leo" line in /var/log/messages, but NEVER a /tmp/leo_stop or a "stopping leo" message, nor a mail for root, or smthing like that.
So it seems that the script is never executed by the system with a "stop" parameter when the server is rebooted. And that the K01leonardo links are unuseful...
What am I missing???
Many thanks in advance to everybody.
Leonardo.
12 REPLIES 12
Alexander Chuzhoy
Honored Contributor

Re: Redhat chkconfig script: does the 'stop' ever run?

A typical UNIX system deletes everything in /tmp folder upon boot. Many Linux sysadmins choose to do the same with script or other means.
I'd recomend you to use another folder for your tests.
Regards.
LBertoglio
Advisor

Re: Redhat chkconfig script: does the 'stop' ever run?

No: /tmp contains also old files. Anyway I moved the files creation to /root/leo_xxx, but nothing changed: just the start file appeared after reboot.
Thanks anyway.
L.

Re: Redhat chkconfig script: does the 'stop' ever run?

How do you reboot the server?
LBertoglio
Advisor

Re: Redhat chkconfig script: does the 'stop' ever run?

With the "reboot" or "shutdown -r now" commands. No differences found using the first or the 2nd one....
/sbin/reboot is a link to halt.
Alpha977
Valued Contributor

Re: Redhat chkconfig script: does the 'stop' ever run?

Ciao Leonardo,

usually when you use chkconfig, the script is copied into /etc/init.d and configured for start/stop into rc.x level.

Check if into /etc/init.d your script is present.

Regards.
Alpha977
Valued Contributor

Re: Redhat chkconfig script: does the 'stop' ever run?

excuse me, bad read!

Sorry


when you reboot the server, the tmp folder became empty.
When you shutdown the system, it go into runlevel 0 and have to kill all the process.
Your script write into tmp the "leo_stop" but this is erased at reboot, infact you can find only the start.


Try to put your start/stop result into another folder and reboot, i'm sure you can find all.


Regards
LBertoglio
Advisor

Re: Redhat chkconfig script: does the 'stop' ever run?

Hi,
file creation changed to /root ; and anyway /tmp is not emptyed at boot, so it seems. And yes, the script "leo" is in /etc/init.d.
But no good news after the reboot.
Some other suggestions?
Many thanks.
Leonardo.
Alexander Chuzhoy
Honored Contributor

Re: Redhat chkconfig script: does the 'stop' ever run?

Hm,
what happens if you execute:
/etc/rc0.d/K01leonardo ?

I suppose it should bring you closer to the solution, i.e. if it'll create the /tmp/leo_stop file, then (unless it's a bug of course) you should consider rewriting your script to create a file in another folder.
LBertoglio
Advisor

Re: Redhat chkconfig script: does the 'stop' ever run?

Hi.
Running as root
/etc/rc0.d/K01leonardo stop
works fine, and create the /root/leo_stop file (as the "new" script version has /tmp changed in /root).
But after the 'shutdown -r now' command is completed, in /root just the leo_start exists. Nothing changed, no leo_stop file!
L.