Set specific services to run

Hello, I have a balena Fin running 4 containers/services, some of my Fin’s only need one of the services. However I would like to keep the same image across all devices - is there a way I can control which services a device runs through service variables on balenaCloud?


One of the things that you can do in balenaCloud is pin a device to a particular release. See more about it here -

Do you think this would work for you? You would have 2 releases for example - and on some devices you’d pin a release with a single container, and on others you’d enable all.

Another thing that you could do is have service variables. These will be accessible to the service when it starts, and based on it’s value you can decide to stop the said service at runtime. See the supervisor API here -

You can interact with the supervisor that manages all the services with a simple HTTP client running on one of your services.

Thanks @anujdeshpande, The second option looks a lot more promising for my use case as I wont require me to track releases across multiple devices

Do you mean uses an HTTP client to make the request to kill all the unused services each time the container is started?

Would there be a way to set a CUSTOM CONFIGURATION VARIABLES in balena Cloud that can be accessed from my docker compose file to stop the service?

Hi Patrick

Can you help me understand a bit more what you mean by that?
The docker compose file is used to build the image on our servers. This image is then downloaded by the devices.

Thanks @anujdeshpande,

After researching a bit more in the supervisor docs I understand, this is a good solution

For anyone else, I put this in my service, I then set the CLIENT_FACING service var in balenaCloud

if [[ ! -z ${CLIENT_FACING} ]]
    echo "Killing un-used services"
    curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/stop-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"serviceName": "redis"}'
    curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/stop-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"serviceName": "cups"}'
    curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/stop-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"serviceName": "websocket"}'
  echo "Keep services running"