Restarting different container from within another container on that device only via API

Hello,

I’m trying to figure out how to restart a container running on one device from another container using the supervisor API. The balena supervisor docs describe a restart endpoint that is a bit of overkill; it will restart the service on the entire fleet. I would like however only to restart the service on the device that the API call is being called from.

I can do this successfully using the balena-cloud API from within a container. This call will call out to balena cloud and command to restart the service, but requires connectivity out to the external endpoint, and then returns back to the local device. The API call is:

curl -X POST --header "Content-Type:application/json" --header "Authorization: Bearer $EXTERNAL_BALENA_API_TOKEN" --data '{ "uuid" : <device uuid>, "data" : { "serviceName" : <local-service-name> } }' "https://api.balena-cloud.com/supervisor/v2/applications/$BALENA_APP_ID/restart-service"

I’d like to just be able to do this from within the device itself.

Hello @richard.galvez that’s a good question!

My recommendation is to use the supervisor API to reboot another container. Did you try this? Interacting with the balena Supervisor - Balena Documentation

You will need to have the supervisor-api label on your docker-compose → Multiple containers - Balena Documentation

@richard.galvez i was wrong with the previous link.

To restart a service from one specific device using the supervisor API use this → Interacting with the balena Supervisor - Balena Documentation

curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/restart-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"serviceName": "my-service"}'

Let us know if that works!