sibbl / hass-lovelace-kindle-screensaver

This tool generates a png from a Home Assistant Lovelace view, which can be displayed on a Kindle device which has the Online Screensaver plugin installed.
MIT License
333 stars 74 forks source link

Feature request - Stop container exiting after error #113

Open andyb2000 opened 7 months ago

andyb2000 commented 7 months ago

Perhaps changing how the run.sh operates so it's in a loop rather than when it exits the docker container closes, so in an error situation the container completely closes. If it were to be in a loop then the container would stay UP but keep retrying which may get around occasional errors in fetching, rendering, etc.

(I think this is how docker runs the run.sh in the init scripts like this: {rc.init} /bin/sh -e /run/s6/basedir/scripts/rc.init top /run.sh So when run.sh exits as thats the end of the init/run scripts it shuts the container down)

sibbl commented 7 months ago

Isn't this what the "Watchdog" option in Hass Add-Ons is for? To auto-restart the container after it crashed?

But I still like the idea for small errors like rendering timeouts, which happen occasionally. Maybe some error count or other back off mechanism would make sense though. I'd also suggest to rather implement it using a try-catch in the JS code instead of the run.sh. We have more control and more logic available there over what went wrong and how to deal with it.

andyb2000 commented 7 months ago

The problem with the watchdog is that it will go into a race condition with this, so in an error the container is constantly restarting which is very system heavy. Better I think we try and catch the errors to a degree in our main run.sh and only exit in fatal errors or certain conditions.

You're right, trying to do it at run.sh level is a bit harsh. As soon as run.sh exits then the container gets destroyed which is a good failsafe mechanism, but yes if we can use try methods in the JS index.js instead that should cope much better.

Not sure how your time is but I've got a little time free so I'm trying a few things out in my branch repo https://github.com/andyb2000/hass-lovelace-kindle-screensaver/tree/andyb2000-fixes so will give those a go (also trying to fix the dither option as seems to be wanting more than a boolean despite docs saying so)