Automation to restart docker container on some trigger

903 Views Asked by At

I have a problematic docker container on my media server (plex/xTeVe running on Synology NAS) that likes to stop responding to requests but is otherwise healthy (doesn't fail docker-compose healthchecks).

Is there a way to develop a trigger that can automatically restart this container? I have a webserver and am comfortable hosting other home automation tools to make this possible. I just haven't found a viable option yet. Bonus points if this can be spouse-friendly so when another family member runs into a media server problem, they can have a simple trigger to use to restart the container without having to understand the technical aspects (simple webpage, physical home automation button, Alexa command, etc.).

I'd love to hear any and all suggestions! Thanks!

1

There are 1 best solutions below

0
Bahram Ardalan On

Use cron to periodically run a checking/monitoring shell script and react to detected conditions/events.

Modern media servers normally serve some playlist thru http, thus, to detect availability, you may simply use curl to check server response for a certain URL with small timeout then decide to do a 'docker restart container_name' if you got no or bad response.

Notes:

  • You don't need a loop and an open session because corn does that for you.
  • Use vi my_script.sh to create your script
  • Use crontab -e to add your script to cron table