# Delete Application inside a service

**URL:** <https://forums.balena.io/t/delete-application-inside-a-service/218633>\
**Category:** openBalena\
**Created:** [December 7, 2020, 9:00am UTC](https://forums.balena.io/t/delete-application-inside-a-service/218633 "2020-12-07T09:00:19Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![scarlyon](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@scarlyon](https://forums.balena.io/u/scarlyon)\
**Post date:** [December 7, 2020, 9:00am UTC](https://forums.balena.io/t/delete-application-inside-a-service/218633/1 "2020-12-07T09:00:19Z")

</div>

I’d like to delete all running containers inside a service(balena supervisor API is enabled) when an event is triggered.

How can I do this so that balena supervisor will be stopped and all other services(including the service that triggered this action)?

Cheers.

---

<div class="post-metadata">

**Author:** ![zvin](https://avatars.discourse-cdn.com/v4/letter/z/a5b964/32.png) [@zvin](https://forums.balena.io/u/zvin)\
**Post date:** [December 7, 2020, 12:47pm UTC](https://forums.balena.io/t/delete-application-inside-a-service/218633/3 "2020-12-07T12:47:03Z")

</div>

Hello,

You can use [https://www.balena.io/docs/reference/supervisor/supervisor-api/#post-v2applicationsappidstop-service](https://www.balena.io/docs/reference/supervisor/supervisor-api/#post-v2applicationsappidstop-service) to stop a running service.

I don’t think you can stop the supervisor completely and I’m not sure if stopping the container itself will work (probably yes).

You can use the `io.balena.features.balena-socket` label for getting access to the docker socket to be able to delete containers and images ( see [https://www.balena.io/docs/learn/develop/multicontainer/#labels](https://www.balena.io/docs/learn/develop/multicontainer/#labels) ).  
I wouldn’t recommend this as the supervisor would download them again.

You can probably stop the `resin-supervisor` service on the hostOS sending a command to systemd through dbus.  
I wouldn’t recommend that either because the supervisor provides most functionality.  
You would need to ssh manually into the host os to start the supervisor again.

---

<div class="post-metadata">

**Author:** ![scarlyon](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@scarlyon](https://forums.balena.io/u/scarlyon)\
**Post date:** [December 7, 2020, 10:11pm UTC](https://forums.balena.io/t/delete-application-inside-a-service/218633/5 "2020-12-07T22:11:35Z")

</div>

Hi, @zvin

Yeah, I want to **completely** stop the supervisor so that the device won’t be able to connect to my openBalena server.

Any other approach to do this?

Cheers.

---

<div class="post-metadata">

**Author:** ![richbayliss](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/richbayliss/32/1054_2.png) [@richbayliss](https://forums.balena.io/u/richbayliss)\
**Post date:** [December 8, 2020, 10:40am UTC](https://forums.balena.io/t/delete-application-inside-a-service/218633/6 "2020-12-08T10:40:59Z")

</div>

You are trying to do something which would prevent our Supervisor from running; we haven’t made a feature of that. You might be able to use DBUS to control systemd and stop the `resin-supervisor` service, then you would want to wipe the `/mnt/boot/config.json` file so that it loses the keys to talk to your instance.

I presume this is for some kind of security tamper trigger?

---

<div class="post-metadata">

**Author:** ![scarlyon](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@scarlyon](https://forums.balena.io/u/scarlyon)\
**Post date:** [December 8, 2020, 10:42am UTC](https://forums.balena.io/t/delete-application-inside-a-service/218633/8 "2020-12-08T10:42:32Z")

</div>

Yeah, for security! 🙂

Thanks for your suggestion!

---

<div class="post-metadata">

**Author:** ![scarlyon](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@scarlyon](https://forums.balena.io/u/scarlyon)\
**Post date:** [December 8, 2020, 10:45am UTC](https://forums.balena.io/t/delete-application-inside-a-service/218633/9 "2020-12-08T10:45:44Z")

</div>

By the way, could you share the exact dbus command to stop the `resin-supervisor` service?

---

<div class="post-metadata">

**Author:** ![richbayliss](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/richbayliss/32/1054_2.png) [@richbayliss](https://forums.balena.io/u/richbayliss)\
**Post date:** [December 8, 2020, 10:50am UTC](https://forums.balena.io/t/delete-application-inside-a-service/218633/10 "2020-12-08T10:50:02Z")

</div>

there is nothing special / balena-specific about DBUS controlling systemd. You will need to find the code specific to your programming environment (Node, Python etc) – here is an example of how the Supervisor stops a service; [https://github.com/balena-io/balena-supervisor/blob/17cf330771b0fa6e8b7aa22a4a245e7e3679abf8/src/lib/avahi.ts#L26](https://github.com/balena-io/balena-supervisor/blob/17cf330771b0fa6e8b7aa22a4a245e7e3679abf8/src/lib/avahi.ts#L26)

You just need to expose the DBUS socket to the containered process running the code; see [https://www.balena.io/docs/learn/develop/runtime/#dbus-communication-with-host-os](https://www.balena.io/docs/learn/develop/runtime/#dbus-communication-with-host-os)

---

<div class="post-metadata">

**Author:** ![richbayliss](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/richbayliss/32/1054_2.png) [@richbayliss](https://forums.balena.io/u/richbayliss)\
**Post date:** [December 8, 2020, 10:50am UTC](https://forums.balena.io/t/delete-application-inside-a-service/218633/11 "2020-12-08T10:50:42Z")

</div>

Good luck on your security tripwire, I would be interested to see what you do/come up with if you’re happy to make it public 👍

---

<div class="post-metadata">

**Author:** ![scarlyon](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@scarlyon](https://forums.balena.io/u/scarlyon)\
**Post date:** [December 8, 2020, 10:51am UTC](https://forums.balena.io/t/delete-application-inside-a-service/218633/12 "2020-12-08T10:51:54Z")

</div>

Ok, will give it a try.

Thanks!

---

<div class="post-metadata">

**Author:** ![scarlyon](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@scarlyon](https://forums.balena.io/u/scarlyon)\
**Post date:** [December 10, 2020, 9:25am UTC](https://forums.balena.io/t/delete-application-inside-a-service/218633/16 "2020-12-10T09:25:58Z")

</div>

Hi, @richbayliss

I was able to stop the `resin-supervisor` service inside a container.

However, how can I delete `/mnt/boot/config.json`(hostOS) inside a container?

Cheers,  
Shane.

---

<div class="post-metadata">

**Author:** ![majorz](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/majorz/32/639_2.png) [@majorz](https://forums.balena.io/u/majorz)\
**Post date:** [December 10, 2020, 4:44pm UTC](https://forums.balena.io/t/delete-application-inside-a-service/218633/18 "2020-12-10T16:44:58Z")

</div>

Hi, we do not provide a mechanism for modifying config.json from inside a container yet.  
Thanks,  
Zahari
