I have a digital signage app and I’d like to restart the chromium frontend container every 24hrs to keep it fresh. I tried using chron and rebooting the system but this is causing issues with the x system.
What’s the cleanest way to restart a container periodically?
@jason10, the use of the supervisor API mentioned in this thread takes place through either:
A localhost connection within the device itself (between docker containers), to the address exposed through the ${BALENA_SUPERVISOR_ADDRESS} environment variable (currently a value of "http://127.0.0.1:48484"). For security reasons, this connection / port number is not exposed to the local network by the Host OS, so a local network server/controller could not initiate a connection to the device’s supervisor (but see alternatives below).
A connection from any controller machine anywhere in the world (including the device’s local network…) to the balena API at api.balena-cloud.com. This requires the device under control (e.g. the device running the contrainer you wish to restart) to have a functional internet connection so it can receive commands from balena’s cloud service.
It sounds like you are describing a scenario in which the device has a good local network connection, but an unreliable internet connection and thus often “offline” from the point of view of balena’s cloud. You then ask whether a server/controller machine on the same local network as the device could use the device’s supervisor API to restart a container. As explained above, the device’s Host OS does not expose the supervisor API port to the local network. However, you could get around this by having the device initiate a connection to your local server/controller. For example, this could be a cron job in a single container app, or some dedicated watchdog container in a multicontainer app for increased reliability. Such local controlling connection could be a regular polling or a long-lived permanent connection – totally under your control. Once a connection has been established, the server/controller can instruct the device to forward commands to the supervisor, including a command to restart a container.
@pdcastro I’m trying to do this but cron doesn’t seem to have access to the environment variables. When I run the script manually it works but with cron the script runs(I can see the echo) but the ${BALENA_SUPERVISOR_ADDRESS} variable returns blank.
@Medistream I think it might depend on how you’re starting cron, but what you could do in any case is, in your container’s start script, save the envrionment to a file env > cron_env_file and then add source cron_env_file before the command you want to run in the cronfile.