Newb question regarding fleets, devices, and services

Hi. I have a very general question about fleets and devices. I am using balena-fin for my project as well as balena cloud. Before moving to this platform, my iot devices were pi3s running a number of applications. My system has about 6-8 applications that may or may not be required depending on the specific use case. The way I have been managing this is to use systemd to disable un-needed applications.

As I am migrating to balenaOS, I am adapting each application into its own container. I should mention that I think I prefer this method rather than enabling dbus and systemd and running all my services in a single container. I realize this would most closely model my current deployment method, but I do want to gain the benefit of isolating the individual services.

I’ve got a few of them migrated and note that each time I add a device to the fleet, all the containers are deployed and started.

Given that each site where I deploy a fin will have different requirements in terms of which services it needs, what’s the best practice for managing this with balena cloud? Do I need to create a unique fleet for every permutation of service requirements? Or do I need to add code to each service to check for a device variable to indicate whether the service should run? If not needed, the service could just sleep indefinitely.

I recognize there are several ways to solve this problem, but wondering if there is an established norm or best practice.

Also another question for the group. What’s the best way to ensure that new devices get their proper network (i.e. wifi hotspot and cellular) configuration files? So far I’ve seen that I need to download and flash the image generated by the balena cloud for my fleet. Once the device checks in, I can then able to go an modify the network config files. Is there a way I can craft the balenaOS img file so that these network config files are already encoded?

Thanks!

1 Like

Hi,

Regarding the multiple services, I think the cleanest way is to check for certain environment variables in your startup scripts and then either idle or exit the services you don’t want to use.
You can set default values for the whole fleet and then add device-specific overrides to fine tune which device runs which services.

Regarding the configuration.
You can use balena-cli to configure your images.
An alternative method I sometimes use (in Linux), is to mount the image on a loopback device and then add the configuration files directly before flashing the device.
For the loopback device I use sudo losetup --find --show --partscan <image>, which will create and print the devices (like /dev/loop19p1) and then just mount the first partition with sudo mount /dev/loop19p1 /mnt and copy the relevant connection files to /mnt/system-connections/.

Hope this helps.

2 Likes

Thanks very much for the feedback. This helps.

1 Like

Thanks @TJvV, this is great advice! And welcome @ericwaynedavis, glad to have you in the community. :slight_smile:

Thanks David. Glad to be here! Very happy with the fin!

1 Like