Quote:
I have tried 12345 as the runlevel in chkconfig and it didn't make any difference.
|
Were you careful to do a "chkconfig --del mytest" first, then a "chkconfig --add mystest"? If you changed the
script and did not --del then --add, the change would not be effective.
Quote:
My hunch is that this scripting procedure was designed to work with ongoing, daemon processes; where our script is
just a script that runs a few things then politely exits.
|
That is not the case. I have this service (see code) and it runs just fine. It just emails a message and exits.
No daemon running.
Code:
#!/bin/bash
#
# mytest Just send an email
#
# chkconfig: 12345 90 10
# description: Just send an email when runlevel changes
#
MAIL="/bin/mailx"
RMAIL="root@`hostname`"
WHO="mytest"
WHERE="`hostname`"
case "$1" in
'start')
[ -f /var/lock/subsys/$WHO ] \
&& logger -ist $WHO "$WHO appears already started"
${MAIL} -s "$WHO starting on $WHERE" ${RMAIL} < /dev/null >/dev/null 2>&1
touch /var/lock/subsys/$WHO
;;
'stop')
[ -f /var/lock/subsys/$WHO ] \
|| logger -ist $WHO "$WHO appears already stopped"
${MAIL} -s "$WHO stopping on $WHERE" ${RMAIL} < /dev/null >/dev/null 2>&1
/bin/rm -f /var/lock/subsys/$WHO
;;
*)
echo "Usage: $0 { start | stop }"
exit 1
;;
esac
exit 0
Quote:
The perl script in question does know about "stop" and "start".
|
Cool. Most people keep their start and stop logic in separate files, but that's personal preference.
Quote:
... But it will not run any commands when the system is being shutdown and when, presumably, the script is being
issued a "stop" by chkconfig at the appropriate time.
|
A slight misconception. 'chkconfig' does not drive your script nor issue a 'stop' to it.
'chkconfig' is a small utility that creates and manipulates the stop and start softlinks that the 'init' process
drives when you change runlevels. On a "chkconfig --add <service>", it reads the shell script for that service
in /etc/rc.d/init.d, and based on the "# chkconfig:" comment, generates "K" and "S" softlinks in the /etc/rc.d/rc0./
through /etc/rc.d/rc6.d/ directories pointing back to the script in /etc/rc.d/init.d.
As an example, when you did the "chkconfig --add mytest", it would have made certain first that the "mytest" was
in /etc/rc.d/init.d and was executable; then it would have read it to get the "# chkconfig: 012345 12 02" comment;
and finally would have created softlinks named "S12mytest" in directories /etc/rc.d/rc0.d through /etc/rc.d/rc5.d
pointing to /etc/rc.d/init.d/mytest, and a softlink named "K02mytest" in /etc/rc.d/rc.6.
With my "mytest", I have.
Code:
[root@athlonz ~]# grep chkconfig: /etc/rc.d/init.d/mytest
# chkconfig: 12345 90 10
[root@athlonz ~]# find /etc/rc* -name \*mytest -exec ls -l {} \;
lrwxrwxrwx 1 root root 16 2010-05-05 09:27 /etc/rc.d/rc1.d/S90mytest -> ../init.d/mytest
lrwxrwxrwx 1 root root 16 2010-05-05 09:27 /etc/rc.d/rc5.d/S90mytest -> ../init.d/mytest
-rwxr-xr-x 1 root root 709 2010-05-05 09:31 /etc/rc.d/init.d/mytest
lrwxrwxrwx 1 root root 16 2010-05-05 09:27 /etc/rc.d/rc0.d/K10mytest -> ../init.d/mytest
lrwxrwxrwx 1 root root 16 2010-05-05 09:27 /etc/rc.d/rc3.d/S90mytest -> ../init.d/mytest
lrwxrwxrwx 1 root root 16 2010-05-05 09:27 /etc/rc.d/rc4.d/S90mytest -> ../init.d/mytest
lrwxrwxrwx 1 root root 16 2010-05-05 09:27 /etc/rc.d/rc2.d/S90mytest -> ../init.d/mytest
lrwxrwxrwx 1 root root 16 2010-05-05 09:27 /etc/rc.d/rc6.d/K10mytest -> ../init.d/mytest
[root@athlonz ~]#
With your original "mytest".
Code:
[root@athlonz ~]# grep chkconfig: /etc/rc.d/init.d/mytest.orig
# chkconfig: 012345 12 02
[root@athlonz ~]# find /etc/rc* -name \*mytest.orig -exec ls -l {} \;
lrwxrwxrwx 1 root root 21 2010-05-05 11:17 /etc/rc.d/rc1.d/S12mytest.orig -> ../init.d/mytest.orig
lrwxrwxrwx 1 root root 21 2010-05-05 11:17 /etc/rc.d/rc5.d/S12mytest.orig -> ../init.d/mytest.orig
-rwxr-xr-x 1 root root 990 2010-05-05 11:17 /etc/rc.d/init.d/mytest.orig
lrwxrwxrwx 1 root root 21 2010-05-05 11:17 /etc/rc.d/rc0.d/S12mytest.orig -> ../init.d/mytest.orig
lrwxrwxrwx 1 root root 21 2010-05-05 11:17 /etc/rc.d/rc3.d/S12mytest.orig -> ../init.d/mytest.orig
lrwxrwxrwx 1 root root 21 2010-05-05 11:17 /etc/rc.d/rc4.d/S12mytest.orig -> ../init.d/mytest.orig
lrwxrwxrwx 1 root root 21 2010-05-05 11:17 /etc/rc.d/rc2.d/S12mytest.orig -> ../init.d/mytest.orig
lrwxrwxrwx 1 root root 21 2010-05-05 11:17 /etc/rc.d/rc6.d/K02mytest.orig -> ../init.d/mytest.orig
[root@athlonz ~]#
Note the difference for runlevel 0 for both services, /etc/rc.d/rc0.d/K10mytest vs. /etc/rc.d/rc0.d/S12mytest.orig.
Mine is a "K" (kill) script and yours is an "S" (start) script.
When you "shutdown -h", "teleinit 0" or "init 0", you are asking the system to go to runlevel 0; when you "reboot",
"shutdown -r", "telinit 6" or 'init 6", you are asking the system to go to runlevel 6. What is happening is that
'init' gets told "change to runlevel X". What it does is execute a script "/etc/rc.d/rc".
"/etc/rc.d/rc" first executes all of the "K" scripts for the new runlevel, one at a time in numerical order, passing
each one an argument of 'stop'; then executes all of the "S" scripts for the new runlevel, also one at a time and
in numerical order, passing each one an argument of 'start'.
A popular misconception is that it runs the scripts for your current runlevel. In fact, it just does the ones for
the new runlevel.
Take a look at "/etc/rc.d/rc". It is pretty simple. You can see in the "KILL scripts" section (processing the "K"
scripts) that it will bypass any that are missing the "lock file"
Code:
[ -f /var/lock/subsys/$subsys -o -f /var/lock/subsys/$subsys.init ] || continue
And in the "START scripts" section (processing the "S" scripts), it will bypass any that already have a lock file.
Code:
[ -f /var/lock/subsys/$subsys -o -f /var/lock/subsys/$subsys.init ] \
&& continue
When the system comes back from the shutdown or reboot, 'init' looks at "/etc/inittab" for the default runlevel
(or uses an overriden value), then drives the "/etc/rc.d/rc" script just as it did at shutdown.
You can see from this scheme that when you "shutdown -h" and your script was added with "# chkconfig: 012345 12 02",
the "/etc/rc.d/rc0.d/S12mytest" script will be executed and passed an argument of 'start'. That's not what you want.
Also, with a "priority" of "12", your script will be invoked well before some of the things it may be dependent on, like the network, if you need to communicate with another system... I always use a pretty high number for starting a service -- in the 90's, and a low one for stopping -- in the zero's or 10's.
Unfortunately, I wasn't able to get your script to work. I spent about two hours on it, and I'm stubborn, but
there's a limit... I suspect there is something funky about the lock file handling. My testing would only invoke
the stop scripts! I couldn't get it to invoke the start scripts. The exact opposite of your experience.
I'd suggest using the script I supplied above and see if that will work.
I'm interested in a resolution if you find one. Good luck.