Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a custom service that I need started after mysql comes online. I am attempting to use systemd/systemctl to start the service at boot. I have set After=network.target mysqld.service in my custom configuration file. What appears to be the problem is systemctl believes mysql has finished starting and therefore proceeds to start my custom service but custom service fails to the connect to the database, after reviewing the log. Checking the timestamps on the mysql log it shows that my custom service is starting before mysql is ready to start. I have looks around the documentation of systemctl and there does not appear to be any "wait before starting timeout" or "wait until a socket is listening for connections". How can I ensure mysql is ready before my custom service starts?

share|improve this question
    
add a delay to the start? –  soandos Apr 20 '12 at 0:20
    
Where? systemctl configuration files don't have a sleep –  Dan S Apr 20 '12 at 0:37
    
Apparently, there's a bug in mysql's unit file wherein systemd thinks its started before it actually is. You should file it. To use soandos' workaround, you can add something like ExecStartPre=/bin/sleep 10. –  Patches Apr 28 '12 at 15:36

1 Answer 1

There is an option in systemd.service files, that explicitly checks for the existing of the socket.

In the systemd documentation Lennart Pöttering goes great length to describe that most services don't need the actual deamon started, but just the socket to bind to.

Systemd can create those sockets, and starts mysql on first access! This is one of the main reasons, systemd was created.

http://0pointer.de/blog/projects/socket-activation.html

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.