start a service only after mysql has entered Active (running) state

Posted October 16, 2017 7.5k views

I have a service that requires mysql to be fully up and running before it starts otherwise it fails. I have very alrge mysql databases and mysqld takes up to 40 minutes before entering an active (running) state.

I have tried adding After=mysqld.service in the secondary services .service file {unit] section without success. It starts my secondary service ass soon as mysqld is enabled. I have tried using Wants=mysqld.service and Requires=mysqld.service without success.

Any help or suggesstions would be appreciated.

Thank you

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Generally, to declare a strict dependency, you will want both After and Requires:

Description=My application 

If for some reason you’re still not have the expected behavior, another option would be to use a script in ExecStartPre that blocks until it can connect to the database. wait-for-it is a useful tool for this:

For more info on working with systemd unit files, check out:

by Justin Ellingwood
Increasingly, Linux distributions are adopting or planning to adopt the systemd init system. This powerful suite of software can manage many aspects of your server, from services to mounted devices and system states. In systemd, a unit refers to any resource that the...