# Selectively disable services on a per-device basis?

**URL:** <https://forums.balena.io/t/selectively-disable-services-on-a-per-device-basis/22807>\
**Category:** balenaEngine\
**Created:** [July 31, 2019, 1:07pm UTC](https://forums.balena.io/t/selectively-disable-services-on-a-per-device-basis/22807 "2019-07-31T13:07:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![psychlist](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/psychlist/32/1369_2.png) [@psychlist](https://forums.balena.io/u/psychlist)\
**Post date:** [July 31, 2019, 1:07pm UTC](https://forums.balena.io/t/selectively-disable-services-on-a-per-device-basis/22807/1 "2019-07-31T13:07:29Z")

</div>

I’d like to be able to disable services (containers) selectively on a per-device basis using environment variables. Is there a built in way of doing this?

Failing that, is there a Supervisor API method for disabling services, ideally one that survives reboots?

Reason: my application contains several independent functions, and I’d like to be able to disable them on a per-device basis.

Thanks.

---

<div class="post-metadata">

**Author:** ![hedss](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/hedss/32/210_2.png) [@hedss](https://forums.balena.io/u/hedss)\
**Post date:** [July 31, 2019, 2:24pm UTC](https://forums.balena.io/t/selectively-disable-services-on-a-per-device-basis/22807/4 "2019-07-31T14:24:26Z")

</div>

Hello,

Thanks for your question.

There isn’t currently a way to do this, via envvars or not, for a balenaCloud application, as the Supervisor API only supports the starting/stopping/restarting of entire applications rather then the container, instead of disabling specific services. We don’t expose the balenaEngine socket to any containers, so unfortunately you also can’t do it manually.

There is a way to do this if you’re using local mode (ie. for development), which is to use the state endpoints of the Supervisor to post a new state (and you’d remove the relevant service containers from your newly POSTed state to stop them from being run). The local mode endpoints are documented [here](https://github.com/balena-io/balena-supervisor/blob/master/docs/API.md#local-mode-endpoints) although as it notes, they’re not intended for general use.

That said, we do have have several customers that do something similar, but they carry out inter-service communication at initialisation to determine which services should continue to run or which should just stop. This doesn’t stop the service containers from being started, but does mean they don’t execute their function.

I’m going to raise an internal issue to moot the prospect of service disabling, but this does carry with it several architectural questions (for example, what to do in the event of a new release of an application).

Best regards, Heds

---

<div class="post-metadata">

**Author:** ![hedss](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/hedss/32/210_2.png) [@hedss](https://forums.balena.io/u/hedss)\
**Post date:** [July 31, 2019, 2:27pm UTC](https://forums.balena.io/t/selectively-disable-services-on-a-per-device-basis/22807/5 "2019-07-31T14:27:28Z")

</div>

Hi again,

I’m actually incorrect and we _do_ have an endpoint for stopping an independent service:

> <https://github.com/balena-io/balena-supervisor/blob/master/docs/API.md#stop-a-service-post-v2applicationsappidstop-service>

as well as starting a service again:

> <https://github.com/balena-io/balena-supervisor/blob/master/docs/API.md#start-a-service-post-v2applicationsappidstart-service>

Given this, you could have a manager service which itself then determines when a service should be started based on envvars to that service.

Apologies for the incorrect advice, I’d completely missed those endpoints!

Best regards, Heds

---

<div class="post-metadata">

**Author:** ![psychlist](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/psychlist/32/1369_2.png) [@psychlist](https://forums.balena.io/u/psychlist)\
**Post date:** [July 31, 2019, 5:29pm UTC](https://forums.balena.io/t/selectively-disable-services-on-a-per-device-basis/22807/8 "2019-07-31T17:29:44Z")

</div>

Thanks so much for the fast responses. I’ll use the supervisor API route – I already have a service that can act as an orchestrator for the other services, and I can drive its behaviour using ENV vars.

This is a fantastic platform and toolset. The more I use it, the more impressed I am.

Cheers,  
Peter

---

<div class="post-metadata">

**Author:** ![sradevski](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/sradevski/32/1609_2.png) [@sradevski](https://forums.balena.io/u/sradevski)\
**Post date:** [July 31, 2019, 5:32pm UTC](https://forums.balena.io/t/selectively-disable-services-on-a-per-device-basis/22807/9 "2019-07-31T17:32:37Z")

</div>

Thanks Peter, we constantly try to reduce the friction to do edge computing, so you can focus on more important things. Hope it works well for you, feel free to get back to us if you need any additional help.

Cheers,  
Steve
