Read Device Variables, without having to restart the service

I’m maintaining a Node.js application running on Raspbery pi 3. The Pi’s are playing audio 24/7 - and I would like to control the volume through the environment variables.

It’s working, but every time I update a device variable, the service restarts(!).

Is this something that could be changed from Balenas side, or would there be another way? I the past I used to read the volume setting from a database, but it seems like overkill. The best part is no part :sweat_smile:

Hey Alex,

Changing environment variables will restart the container(s) by design, to bring the new value into the container environment. It’s not something we can, or want to, stop happening.

In order to change values in your node application, the simplest way would be to implement an API using express. You can find an example here :

Another is here :

Notice that this second example is balenaSound setting the volume of the underlying audio balenaBlock. It may be worth you investigating if you can change your application to use the block. :slight_smile:

Hope this helps,
Phil

Roger :+1: I will use the API approach then

I find the fact that the containers restart automatically very helpful for some of my variables, but I’d see a lot of value in making that behavior optional. Perhaps a toggle that says “restart on change.”

My app maintains state in memory and that is lost when the container restarts, so I’d love to be able to update certain variables without losing state.

I think both behaviors are useful, so add me to the list of feature requesters :slight_smile:

Hey @archetypesc, I’ve noted your request but the current restart behaviour is core to the way containers work. If using Docker on desktop there is no way to update the environment of the container without restarting it. I think an API as my colleague suggested is a good workaround as it wouldn’t depend on environment variables in the container namespace, but could be controlled via a webserver or API endpoint. Does this make sense?