Delete Application inside a service

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.

Hello,

You can use 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 ).
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.

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.

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?

Yeah, for security! :slight_smile:

Thanks for your suggestion!

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

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

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

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 :+1:

Ok, will give it a try.

Thanks!

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.

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