Restart container every 24 hours


#1

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?


Docker container cannot access dynamically plugged USB devices
#6

Hi. You could use the supervisor API to restart the container. See https://docs.resin.io/reference/supervisor/supervisor-api/#post-v1-restart for examples (you could have your application itself restart after 24 hours for example or you can do that remotely)


#7

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


#8

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


#9

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?


#10

Hi. See https://docs.resin.io/reference/supervisor/supervisor-api/#http-api-reference (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)


#12

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.


#13

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

Regards,
Paulo