I have written a service, which should start only after MySQL service starts as the instance boots.
Operating System: Centos 6.10.
How to make the service wait until MySQL service starts completely on boot?
I tried creating startup service in /etc/init.d
startup service script :
# chkconfig: 345 99 01
# description: service startup script
### BEGIN INIT INFO
# Required-Start: mysqld
### END INIT INFO
cd /path_of_server
./start.sh
The issue I am facing is, my service executes before MySQL service starts completely.
2
Answers
This might help you:
systemctl has an is-active subcommand for this:
will exit with status zero if service is active, non-zero otherwise, making it ideal for scripts:
If you omit –quiet it will also output the current status to its standard output.
Make an infinite loop in the shell script and check whether MySQL is running or not using above command inside a loop.
As soon as you find the MySQL running start your service and exit from a loop or script.
Please go through this repository & take look at the wait-fot-it.sh
You have to add wait-for-it.sh script file with your respected script file and put
./wait-for-it.sh mysql:3306 --timeout=30
before start logic of your service script file. Hope it helps.