LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices

Reply
 
LinkBack Search this Thread
Old 05-03-2007, 10:19 AM   #1
Qwerty9119
LQ Newbie
 
Registered: Aug 2006
Posts: 13

Rep: Reputation: 0
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
 
Old 05-03-2007, 12:11 PM   #2
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 5,770
Blog Entries: 4

Rep: Reputation: 697Reputation: 697Reputation: 697Reputation: 697Reputation: 697Reputation: 697
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.
 
Old 05-03-2007, 12:51 PM   #3
Qwerty9119
LQ Newbie
 
Registered: Aug 2006
Posts: 13

Original Poster
Rep: Reputation: 0
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!
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to register auto start/stop service script with chkconfig travellers Linux - Software 8 06-15-2009 11:02 AM
Permissions on script sudo ln -s ../init.d/start-networking S90start-networking cnolasco Ubuntu 3 04-03-2007 08:27 AM
pure-ftpd init script fails to start server in standalone mode Cronjob Debian 1 05-23-2006 12:11 AM
using cron to start and stop a bash script monty Linux - Software 2 03-20-2006 02:30 PM
need a perl script to stop & start program cccc Programming 43 07-23-2005 07:27 PM


All times are GMT -5. The time now is 11:58 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration