Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do make the service wait until MySQL service starts on boot?

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.

like image 800
Aniket Bare Avatar asked Nov 07 '22 17:11

Aniket Bare


1 Answers

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.

like image 108
Akshay Pethani Avatar answered Dec 05 '22 11:12

Akshay Pethani