Mysql service never comes up healthy in action #27021
-
At some point in the last couple weeks, the mysql:5.7 service config I was using to expose mysql to my action stopped working. Here’s the config I’m using:
That config was working perfectly fine for a week or two and then, seemingly out of nowhere, it started failing consistently with the service reporting (almost immediately) that mysql is unhealthy:
As I mentioned, that final error ( Anyone know what I might be missing to get this to work? |
Beta Was this translation helpful? Give feedback.
Replies: 12 comments
-
Hi peburrows, Glad to hear you in Github Community Forum! I copied your code and reproduced the issue. After i add ‘jobs.<job_id>.services.env’ to the service, the error is gone, code as below, hope it helps, thanks.
|
Beta Was this translation helpful? Give feedback.
-
Awesome, thank you! That seems to have fixed it. |
Beta Was this translation helpful? Give feedback.
-
Just for future reference for others that might run into this issue. I had an action that setup a postgres and a redis service. This was what the service code looked like in my main.yml:
It had been running completely fine for a few weeks and then out of the blue the setup of the redis server start failing with the roughly the same issue.
I came across this post and thought it wasn’t relevant at first. After much testing I tried setting up my redis service through another Action from the marketplace. At that point my **postgres** service started failing with the same message above!
Roughly following the advice from this thread I added an .env section with passwords, username, and db env variables to my postgres service. It worked! This is what the code looks like now:
Hope this is helpful for future devs. Also no clue why this suddenly started happening. Nothing changed in my code that would have affected this. |
Beta Was this translation helpful? Give feedback.
-
I just had same issue with postgres 11, running fine for weeks then today: “Failed to initialize, db service is unhealthy”. Just started about an hour ago. This is only thing I found on web that discusses this. Adding the env part worked first time! Thank you very much! |
Beta Was this translation helpful? Give feedback.
-
Same here, my postgres container stopped working, this fixed it. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Hey can you show the changes you have done on script? thanks |
Beta Was this translation helpful? Give feedback.
-
That fixed the container step, but in my rails db:prepare step, I was suddenly getting an issue about a missing postgres password. Make sure to include the env’s:
for any other step that needs postgres, such as:
|
Beta Was this translation helpful? Give feedback.
-
Thank you! This resolved my issue. |
Beta Was this translation helpful? Give feedback.
-
It seems that github actions no longer passes the job:env to services, and that you have to replicate the service env vars. ie, this used to work:
but now you have to repeat the env for the service:
Github: stop making it hard to DRY!!! |
Beta Was this translation helpful? Give feedback.
-
Another happy postgres user whose CI action mysteriously stopped working and found this thread. Thanks for getting me running again! |
Beta Was this translation helpful? Give feedback.
-
I’d tried all of the suggestions here, but still received the same error. Maybe it had something to do with me using mysql:5.6 instead of a higher version like I see being used in every snippet. Anyway, after moving the environment variables to the service, using the MySQL server image did the trick for me:
|
Beta Was this translation helpful? Give feedback.
-
Here's what worked for me:
- name: Check MySQL health status
id: check_health
run: |
echo "Checking MySQL health status..."
attempt_counter=0
max_attempts=24
until [ "$(docker inspect --format="{{.State.Health.Status}}" my_container)" == "healthy" ]; do
if [ ${attempt_counter} -eq ${max_attempts} ];then
echo "Max attempts reached"
exit 1
fi
health_status=$(docker inspect --format="{{.State.Health.Status}}" my_container)
echo "Current MySQL health status: ${health_status}"
if [ "${health_status}" != "healthy" ]; then
echo "Displaying last 10 lines from Docker logs:"
docker logs --tail 10 my_container
fi
attempt_counter=$(($attempt_counter+1))
sleep 5
done |
Beta Was this translation helpful? Give feedback.
Hi peburrows,
Glad to hear you in Github Community Forum!
I copied your code and reproduced the issue. After i add ‘jobs.<job_id>.services.env’ to the service, the error is gone, code as below, hope it helps, thanks.