-
Notifications
You must be signed in to change notification settings - Fork 3k
fix(mysql): ensure MySQL socket symlink is created and wait for MySQL to start #2597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,6 +26,20 @@ services: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /usr/local/bin/docker-entrypoint.sh mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci & | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MYSQL_PID=$$! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mkdir -p /var/run/mysqld 2>/dev/null || true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for i in $(seq 1 30); do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ -S /var/lib/mysql/mysql.sock ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+30
to
+32
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sleep 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ -S /var/lib/mysql/mysql.sock ] && [ ! -e /var/run/mysqld/mysqld.sock ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+31
to
+38
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for i in $(seq 1 30); do | |
| if [ -S /var/lib/mysql/mysql.sock ]; then | |
| break | |
| fi | |
| sleep 1 | |
| done | |
| if [ -S /var/lib/mysql/mysql.sock ] && [ ! -e /var/run/mysqld/mysqld.sock ]; then | |
| # Ensure the socket symlink exists early; dangling is acceptable. | |
| if [ ! -S /var/run/mysqld/mysqld.sock ]; then | |
| ln -sf /var/lib/mysql/mysql.sock /var/run/mysqld/mysqld.sock 2>/dev/null || true | |
| fi | |
| for i in $(seq 1 30); do | |
| # If the MySQL socket appears during the wait, re-ensure the symlink. | |
| if [ -S /var/lib/mysql/mysql.sock ] && [ ! -S /var/run/mysqld/mysqld.sock ]; then | |
| ln -sf /var/lib/mysql/mysql.sock /var/run/mysqld/mysqld.sock 2>/dev/null || true | |
| echo 'Socket symlink ensured' | |
| break | |
| fi | |
| if [ -S /var/lib/mysql/mysql.sock ]; then | |
| break | |
| fi | |
| sleep 1 | |
| done | |
| # Final safeguard to ensure the symlink exists once MySQL is up. | |
| if [ -S /var/lib/mysql/mysql.sock ] && [ ! -S /var/run/mysqld/mysqld.sock ]; then |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ln failures are ignored (2>/dev/null || true) but the script still prints Socket symlink ensured, which can report success even if the symlink wasn’t actually created. Consider letting ln fail loudly or gating the success message on ln’s exit code.
| ln -sf /var/lib/mysql/mysql.sock /var/run/mysqld/mysqld.sock 2>/dev/null || true | |
| echo 'Socket symlink ensured' | |
| if ln -sf /var/lib/mysql/mysql.sock /var/run/mysqld/mysqld.sock 2>/dev/null; then | |
| echo 'Socket symlink ensured' | |
| else | |
| echo 'Failed to ensure socket symlink' >&2 | |
| fi |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,6 +26,19 @@ services: | |||||||||||||||||
| /usr/local/bin/docker-entrypoint.sh mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci & | ||||||||||||||||||
| MYSQL_PID=$$! | ||||||||||||||||||
|
|
||||||||||||||||||
| mkdir -p /var/run/mysqld 2>/dev/null || true | ||||||||||||||||||
| for i in $(seq 1 30); do | ||||||||||||||||||
| if [ -S /var/lib/mysql/mysql.sock ]; then | ||||||||||||||||||
| break | ||||||||||||||||||
| fi | ||||||||||||||||||
| sleep 1 | ||||||||||||||||||
| done | ||||||||||||||||||
|
Comment on lines
+30
to
+35
|
||||||||||||||||||
|
|
||||||||||||||||||
| if [ -S /var/lib/mysql/mysql.sock ] && [ ! -e /var/run/mysqld/mysqld.sock ]; then | ||||||||||||||||||
| ln -sf /var/lib/mysql/mysql.sock /var/run/mysqld/mysqld.sock 2>/dev/null || true | ||||||||||||||||||
| echo 'Socket symlink ensured' | ||||||||||||||||||
|
Comment on lines
+38
to
+39
|
||||||||||||||||||
| ln -sf /var/lib/mysql/mysql.sock /var/run/mysqld/mysqld.sock 2>/dev/null || true | |
| echo 'Socket symlink ensured' | |
| ln -sf /var/lib/mysql/mysql.sock /var/run/mysqld/mysqld.sock 2>/dev/null | |
| if [ $$? -eq 0 ]; then | |
| echo 'Socket symlink ensured' | |
| else | |
| echo 'Failed to ensure socket symlink' >&2 | |
| fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There’s trailing whitespace on the blank line after
MYSQL_PID=$$!(line 29) and an extra blank line later (line 43), which makes the YAML harder to review/maintain. Please remove the trailing spaces and collapse redundant blank lines.