Where does balenaOS store environment variables at runtime?

In my start script for a container, I am grabbing some system data, echoing to /etc/profile.d/gateway-rs.sh and then exporting the environment variables with source that are then used for the gateway:

This works for the container, however these are then not available in the web-based shell on balenaCloud.

Where does balenaOS store it’s environment variables? And can I add to them and reload them at runtime without doing so from the balenaCloud device/fleet variables?

Or is there a better way to do this using the supervisor API or some other method I haven’t thought of?

Hey @shawaj, here are other ways to retrieve the environment variables.

  1. You could use balenaCloud API:
    Resources - Balena Documentation

  2. SDK and CLI also use balenaCloud API under the hood to retrieve these:
    balena CLI Documentation - Balena Documentation
    Balena Python SDK - Balena Documentation

  3. Supervisor API should return the environment variables as well:
    Interacting with the balena Supervisor - Balena Documentation
    You need to apply the io.balena.features.supervisor-api label to enable the supervisor API usage in a container.

Maybe you are not able to retrieve these in container because of this missing flag.?

Let us know if you experience issues with any of these options.

Cheers…

Hi @shawaj !

are you running this script in the web terminal on “Host OS” ? or inside a container ?

if it’s in a service container it should work as long as the environment variable is defined globaly or for this service. If it’s in the Host OS you’ll have to figure another way to get those, like @gelbal said

1 Like

Thank you @mathroc for your help! @shawaj did this work for you?