# Set specific services to run

**URL:** <https://forums.balena.io/t/set-specific-services-to-run/174374>\
**Category:** Product support\
**Created:** [August 17, 2020, 10:30am UTC](https://forums.balena.io/t/set-specific-services-to-run/174374 "2020-08-17T10:30:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![PatrickEntabeni](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@PatrickEntabeni](https://forums.balena.io/u/PatrickEntabeni)\
**Post date:** [August 17, 2020, 10:30am UTC](https://forums.balena.io/t/set-specific-services-to-run/174374/1 "2020-08-17T10:30:24Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![anujdeshpande](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/anujdeshpande/32/3155_2.png) [@anujdeshpande](https://forums.balena.io/u/anujdeshpande)\
**Post date:** [August 17, 2020, 10:33am UTC](https://forums.balena.io/t/set-specific-services-to-run/174374/4 "2020-08-17T10:33:59Z")

</div>

Hi

One of the things that you can do in balenaCloud is pin a device to a particular release. See more about it here - [https://www.balena.io/docs/learn/deploy/release-strategy/release-policy/#pin-device-to-a-release](https://www.balena.io/docs/learn/deploy/release-strategy/release-policy/#pin-device-to-a-release)

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.

---

<div class="post-metadata">

**Author:** ![anujdeshpande](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/anujdeshpande/32/3155_2.png) [@anujdeshpande](https://forums.balena.io/u/anujdeshpande)\
**Post date:** [August 17, 2020, 10:37am UTC](https://forums.balena.io/t/set-specific-services-to-run/174374/5 "2020-08-17T10:37:46Z")

</div>

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 - [https://www.balena.io/docs/reference/supervisor/supervisor-api/#post-v2applicationsappidstop-service](https://www.balena.io/docs/reference/supervisor/supervisor-api/#post-v2applicationsappidstop-service)

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

---

<div class="post-metadata">

**Author:** ![PatrickEntabeni](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@PatrickEntabeni](https://forums.balena.io/u/PatrickEntabeni)\
**Post date:** [August 17, 2020, 10:44am UTC](https://forums.balena.io/t/set-specific-services-to-run/174374/7 "2020-08-17T10:44:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![anujdeshpande](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/anujdeshpande/32/3155_2.png) [@anujdeshpande](https://forums.balena.io/u/anujdeshpande)\
**Post date:** [August 17, 2020, 10:51am UTC](https://forums.balena.io/t/set-specific-services-to-run/174374/8 "2020-08-17T10:51:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![PatrickEntabeni](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@PatrickEntabeni](https://forums.balena.io/u/PatrickEntabeni)\
**Post date:** [August 17, 2020, 11:18am UTC](https://forums.balena.io/t/set-specific-services-to-run/174374/10 "2020-08-17T11:18:08Z")

</div>

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 start.sh, I then set the CLIENT\_FACING service var in balenaCloud

```auto
if [[! -z ${CLIENT_FACING}]]
  then
    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"}'
else
  echo "Keep services running"
fi

```
