ShokoServer icon indicating copy to clipboard operation
ShokoServer copied to clipboard

Retry connecting to database when starting

Open Dexil123 opened this issue 5 years ago • 4 comments

So when I reboot my system I always have to restart the Shoko server because the database wasn't available yet when Shoko started. So it would be nice if Shoko server could try to start again after an preset interval.

Dexil123 avatar Jun 18 '19 22:06 Dexil123

You can trigger it via api

da3dsoul avatar Jun 18 '19 22:06 da3dsoul

Yeah, but can it be automated? Now I need to remember every time I reboot I have restart Shoko. Running on Docker btw.

Dexil123 avatar Jun 18 '19 22:06 Dexil123

You can just use docker-compose and use https://docs.docker.com/compose/compose-file/#depends_on

On Wed, Jun 19, 2019, 8:12 AM Dexil123 [email protected] wrote:

Yeah, but can it be automated? Now I need to remember every time I reboot I have restart Shoko. Running on Docker btw.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ShokoAnime/ShokoServer/issues/790?email_source=notifications&email_token=AAHSXJUUO3D74ERUIUKVDALP3FMUBA5CNFSM4HZEHIEKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYADVBQ#issuecomment-503331462, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHSXJQ5M4LZCARPNJBGCS3P3FMUBANCNFSM4HZEHIEA .

Cazzar avatar Jun 18 '19 23:06 Cazzar

I have tried depends on but it doesn't wait until the database is ready. So Shoko is still starting right after it the database container is running but the database is not accessible yet.
See also: https://docs.docker.com/compose/startup-order/ "However, for startup Compose does not wait until a container is “ready” (whatever that means for your particular application) - only until it’s running. "

Dexil123 avatar Feb 10 '21 15:02 Dexil123

Just found this and hope this will be helpful even if the last post is from Feb 2021.

For Shoko I use this in my compose file:

    depends_on:
      mariadb:
        condition: service_healthy

For the DB I added a custom healthcheck so it actually returns a healthy status when it's up:

    healthcheck:
      test: "/usr/bin/mysql --user=<youruser> --password=<yourpassword> --execute \"SHOW DATABASES;\""
      start_period: 1m
      interval: 30s
      timeout: 2s
      retries: 5

maybe you can work with this for your compose file

krbrs avatar May 29 '23 17:05 krbrs

It'll already retry for a minute. https://github.com/ShokoAnime/ShokoServer/blob/984ddf7a43f8bcf7d33dfbc2d8525a8b6d43151f/Shoko.Server/Databases/DatabaseFactory.cs#L79

da3dsoul avatar May 29 '23 18:05 da3dsoul