waitForMySQL polls until MySQL accepts connections or the timeout expires.
(timeout time.Duration)
| 668 | |
| 669 | // waitForMySQL polls until MySQL accepts connections or the timeout expires. |
| 670 | func waitForMySQL(timeout time.Duration) error { |
| 671 | deadline := time.Now().Add(timeout) |
| 672 | for time.Now().Before(deadline) { |
| 673 | // Try connecting without password (fresh) or with password (already configured) |
| 674 | if exec.Command("mysqladmin", "-u", "root", "ping").Run() == nil { |
| 675 | return nil |
| 676 | } |
| 677 | if exec.Command("mysqladmin", "-h", "127.0.0.1", "-u", "root", "-pmysecretpassword", "ping").Run() == nil { |
| 678 | return nil |
| 679 | } |
| 680 | time.Sleep(500 * time.Millisecond) |
| 681 | } |
| 682 | return fmt.Errorf("timed out after %s waiting for mysql", timeout) |
| 683 | } |
| 684 | |
| 685 | func verifyMySQL() error { |
| 686 | log.Println("verifying mysql connection") |