Restarting a service from another service

Hi, I just wanted to check - is it actively possible to restart the services ONLY on a single device from within a container running on that device? From this thread (Restarting different container from within another container on that device only via API - #2 by mpous) it seems like this should very much be possible. However, looking at the linked documentation it’s a little unclear - for example, the endpoint mentioned in Interacting with the balena Supervisor - Balena Documentation seems to be what’s needed, however the description specifically mentions being used to “restart a service in the fleet with the fleet id passed in with the url.” We have no interest in restarting all services within the current device fleet, only within a single device.

1 Like

Hello @fherder could you please explain the use case? i think this is possible. Did you try it? What results did you get?

We’re starting to implement this, so this questions is trying to get more info before we dive in.

Our use case is that we expect the containers, once deployed, to be default air-gapped away from the balena network. If they want to, clients can connect to the internet as necessary for updates, but it’s not the default access mode. We have a REST API/interface we’re building out to support local control of the containers, and what we’re trying to implement is the ability to arbitrarily restart a service ONLY on this device (or even reboot the device itself) from within a privileged container, if the user has sent the right command to the right endpoint. If for some reason the device is connected to the internet, we don’t want a local call to the supervisor API on the device to restart other containers in other devices in the customer fleet.

To be clear, we haven’t tried this yet (working on it now) but we only have one device in the development fleet at the moment, so we don’t want to build out all this assumed functionality just to find out it has disastrous cross-fleet effects.

Hi, to restart an individual service please use the individual stop and start supervisor API calls. The restart supervisor API call will restart all services in the fleet as you mention.

Thanks @alexgg! One final question, the stop API call seems to specify it will stop the service on the device. However, the start API call seems to indicate it will start the service across the fleet. Is that intended behavior? Again, we need to just not be starting containers randomly across other devices.

Hi, I’ve asked for clarification on the scope of start-service. We will respond again with that clarification.

Hi, the start-service endpoint will only start the service on the device. I have amended the API documentation to correct that, thanks.