Restart container every 24 hours

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?

Hi. You could use the supervisor API to restart the container. See for examples (you could have your application itself restart after 24 hours for example or you can do that remotely)

I don’t actually want to restart the application. Just one container(the chrome frontend). Is there a way to do that?

By application I actually meant the container. So you should be able to do just that like I said above

Where do I retrieve the appId from? and should I execute this from inside the container or from another container? any tips on the architecture?

Hi. See (you can also use the uuid of the device just for a sepcific device). And you can use it either from it’s own container or from another container (your choice)

Is there a way to do the restart from a device on the same network (like a local server/controller) connecting to the balena device?

Sometimes the network is not reliable.

@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 ""). 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 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.

Is there something I have to initialize?

@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.

Thanks @pcarranzav that worked