skip to Main Content

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


  1. This might help you:

    systemctl has an is-active subcommand for this:

    systemctl is-active --quiet service
    

    will exit with status zero if service is active, non-zero otherwise, making it ideal for scripts:

    systemctl is-active --quiet service && echo Service is running
    

    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.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search