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.
2 Answers
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 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