LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Red Hat (http://www.linuxquestions.org/questions/red-hat-31/)
-   -   custom init.d script will start but won't stop (http://www.linuxquestions.org/questions/red-hat-31/custom-init-d-script-will-start-but-wont-stop-550983/)

Qwerty9119 05-03-2007 10:19 AM

custom init.d script will start but won't stop
 
Hey all, I've written a custom init.d script that will basically run a script /root/home/scripts/startup on startup and then when the server is shutting down run /root/home/scripts/shutdown.

I've run chkconfig --add testscript and it does have correct sym links for S and K in rc3.d,rc5.d, rc0.d, rc6.0.

Can anybody suggest anything?

Thanks,

Q

#!/bin/bash
#
# chkconfig: 35 75 10
# description: my test server function
#

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

start() {
initlog -c "echo -n TESTSCRIPT starting: "
/root/scripts/startscript
### touch the lock file ###
touch /var/lock/subsys/startscript
touch /var/lock/subsys/stopscript
success $"My test script starting"
echo
}

stop() {
initlog -c "echo -n RUNNING STOPSCRIPT: "
/root/scripts/stopscript
### Remove the lock file ###
rm -f /var/lock/subsys/startscript
rm -f /var/lock/subsys/stopscript
success $"My test script stopping"
echo
}

case "$1" in
start)
start
;;
stop)
stop
;;
status)
status servicename
;;
restart|reload|condrestart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac

exit 0

MensaWater 05-03-2007 12:11 PM

Having just run into similar issue on RHEL script I believe you're doing the lock incorrectly.

The lock name should be the same as the init script itself - not the script you are calling from within the init script.

Your chkconfig shows the init script name is "testscript". You should therefore have the following in start function:

touch /var/lock/subsys/testscript

NOT:

touch /var/lock/subsys/startscript
touch /var/lock/subsys/stopscript

Similarly you should have the following in stop function:

rm -f /var/lock/subsys/testscript

NOT:

rm -f /var/lock/subsys/startscript
rm -f /var/lock/subsys/stopscript


P.S. You're not supposed to post in more than one forum.

Qwerty9119 05-03-2007 12:51 PM

Thank you jlightner!

The lock file was correct. The script ran correctly during shutdown.

Cheers,

Q

PS. I also now know NOT to post more than once!


All times are GMT -5. The time now is 07:49 AM.