Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to start and stop jobs at boot time and shutdown?

Status
Not open for further replies.

Sina

Technical User
Jan 2, 2001
309
CA
hello everyone;

I just wanted to know where to put my start and stop scripts to run the start jobs at the boot time and my stop jobs at shutdown.

for example I like to start my mysql db at start and shutit down when the server is going down.

I like to run this jobs to start mysql when the system is coming up.
/bin/sh -c 'cd /usr/local/mysql; ./bin/safe_mysqld'

And run the
su - oracle -c "/oracle/product/8.1.7/bin/lsnrctl stop"
when the server is going down.
where should I place these lines?


thank you all



 
With Red Hat you will find that you have a /etc/init.d directory, in general startup scripts are placed there and the files are symbolic linked from within the Run Level directories (rc0.d, rc1.d ....... rc5.d & rc6.d inclusive) so lets say your normal runlevel is level 3 (see /etc/inittab for more) then you will probably want your dB up and running at level 2, so create your script "dBscript", make it executable and soft link it to /etc/rc2.d/S??dBscript where ?? is a number. while you are about it soft link the same script to /etc/rc2.d/K??dBscript.

Now if your running Red Hat then you can use the chkconfig command to help you with setting runlevel startup scripts, to use this on your new script you will need to add a couple of lines into the top of your script:

#!/bin/sh
#
# dB start/stop To start & Stop Database
#
# chkconfig: 2345 99 10
# description: Database Start/Stop Script

##########################
script stuff here .......>>>>

This then allows you to do AUTOMAGIC and have the chkconfig command link this script for you by running:

chkconfig --add dBscript
chkconfig --level 2 dBscript on

{note} the 2345 will allow, if requested this script to be set in any of those run levels only.

This will create the following soft links for you:
/etc/rc2.d/S99dBscript & /etc/rc2.d/K10dBscript

See man chkconfig for more info

Good Luck,
Laurie.
 
Thanks Tarn

Here is what is driving me crazy :)

I have 2 scripts that starts and stops a job.

Startscript

#!/bin/csh
su - oracle -c "/jobs/db101start"


my stopscript is

#!/bin/csh
su - oracle -c "/jobs/db102stop"

Now I have created 2 scripts called them startdb101 and stopdb102 and place them in ../init.d

Created sym link for both files with the names of
S10db101start and K10db102stop under .../rc3.d

rebooted the server.

during the reboot, my job starts very nicely and things work fine but when I shutdown, my shutdown job does not run.

Also Not very familar with chkconfig.

thanks much for your input.


 
Ok can you run /etc/init.d/stopdb102 from the command line and the db stops corectly ?

Try moveing it further up like K99stopdb102 as you may be needing more time and running processes avalible while you'r shutting down.

Ummmm ???? ..... /bin/csh ??? tried bash (or should I say /bin/sh?) could be an environment issue?

Sorry a bit late in the day for me ??

re-post after trying the above

Good Luck,
Laurie.
 
Hi Tarn,

Thanks once again.

Ok, should I have both scripts in combined in to one and use a case statement or can I have 2 separte scripts. The reason is that all scripts that I see under /init.d contain both the start and stop parts together, but I would perfere to have them in separte scripts.

But when I have 2 separte scripts and run the

chkconfig --add db10start
chkconfig --level 2 dB10start


chkconfig --add db10Stop
chkconfig --level 2 dB10stop


So now I have 4 softlinks created.

Oh, confused.
All I wanted to do was to be able to run
this script at start up which works fine
Startscript

#!/bin/csh
su - oracle -c "/jobs/db101start"

and run the following just before shutdown.
my stopscript is

#!/bin/csh
su - oracle -c "/jobs/db102stop"

Thanks so much for your help




 
I think the script could be the problem

Here it is
#!/bin/sh
#
# dB start/stop To start & Stop Database
#
# chkconfig: 2345 99 10
# description: Database Start/Stop Script
##########################

# Source function library.

case "$1" in
start)
echo -n "Starting Oracle Database Server: "
su - oracle -c "/db1/dbstart"
echo -n "Starting Oracle Listener: "
su - oracle -c "/db1/lsnrctl start"
echo
;;

stop)
echo -n "Shutting down Oracle:"
su - oracle -c "/db1/lsnrctl stop"
su - oracle -c "/db1/dbshut"
echo
;;

status)
status Oracle
;;

restart)
$0 stop
$0 start
;;

*)
echo "Usage: oracleDbServer {start|stop|restart|status}"
exit 1

esac
exit 0

And I do have the K99jobs in rc6.d

Any idea?

start job works fine but not the shuting down of the db part

 
Hmm... basically what you have looks ok this is the lines from my "generic" oracle init.d script:

case $1 in
'start')
echo "Starting ORACLE..."
su - oracle -c "dbstart"
rm -rf /var/tmp/o
su - oracle -c "lsnrctl start"
;;
'stop')
echo "Stopping ORACLE..."
su - oracle -c "dbshut"
su - oracle -c "lsnrctl stop"
;;
esac

All I do is shut the database before the listner and this always works for me! maybe try swaping around the dbshut & the listner?

If this does not work and you want a full set of tried and tested scripts take a look here:

Good Luck,
Laurie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top