Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

i have installed MySQL NDB cluster. It needs around 2-3 minutes to synchronise the database in between cluster nodes. Once the synchronisation finished only, I can start another application called heartbeat. Therefore in my shell script, I want to check the availability of the ndbd service all the times. Once this service become available, I need to start the heartbeat application in five minute time. Could you please help me to write the script.

share|improve this question

migrated from stackoverflow.com Jul 14 '09 at 22:57

This question came from our site for professional and enthusiast programmers.

2 Answers 2

You could also try using the "wait" bash built-in command.

From "man bash"

wait [n]

Wait for the specified process and return its termination status. n may be a process ID or a job specification; if a job spec is given, all processes in that job’s pipeline are waited for. If n is not given, all currently active child processes are waited for, and the return status is zero. If n specifies a non-existent process or job, the return status is 127. Otherwise, the return status is the exit status of the last process or job waited for.

You script could look something like this:

# send to background
./ndb_startup_script & 

# wait on pid of ndb_startup_script
wait $!

if [ $? -eq 0 ] # assuming 0 is ret code for successful run
then 
    ./heartbeat_startup_script
else 
    # extra stuff to handle error
fi
share|improve this answer

What I'd to is have the ndb script exec another script, so that it's not waiting for the 5 minutes to finish and blocking other services from starting.

## whatever starts ndb
exec heartbeat_startup_script

I've put a sleep 300 (seconds) in here, cause you've specified 5 minutes, but checking if the ndb sync is done would be much better.

##heartbeat_startup_script
sleep 300
heartbeat
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.