Running commands at boot or after boot on HOST OS


I need to make a change to chronyd used by balena OS.
I basically want to ensure chronyd’s configuration points to a shared folder, that my container can mess with.
For that I need to be able to run a chronyd command on the balena OS on boot or during normal operation (automatically) chronyd -f </path>.

Is there a way to run automatically commands on the Balena OS?

Best regards


I’m not sure what configuration settings you are trying to change, but would chronyc running inside your container allow the configuration you need to be altered that way, rather than editing the file?

Hi @maggie0002 ,

You are sugesting that just by installing Chronyc on my container app, that I am able to control the NTP servers defined in Balena OS?

Not sure if I understood correctly or completely.

If that is true, for me would be enough. I just need to reconfigure the NTP servers.

I haven’t tried it, but I suspect the Chronyc CLI would permit it. You would want to check whether it is persistent though. There may also be a need to provide some elevated privileges to grant the container that communicates with the local Chronyd instance.

If you are able to test it, could you let us know the progress?

Hi, I am guessing this is a continuation from a different thread, and the objective is to be able to configure the NTP servers by launching chronyd with a different configuration.

As mentioned in the other comment, balenaOS can configure the NTP servers by adding an entry to config.json. However, we still do not expose this setting via the supervisor, so the only way to change it is to modify config.json directly which is not ideal.

Another option that I didn’t mention in the other thread, is to actually run chronyd in a privileged container. You could stop the hostOS chronyd using dbus on application start and launch chronyd in the application, having complete control over its configuration.

Hi @alexgg alexgg,
Thanks for the quick reply.

We will try this approach, nonetheless we would like to know if, after stopping chronyd in BalenaOs and starting in the app container, it uses the same ntp servers as the app container.
In other words, does the Host follow the chronyd running in the app container?
Is there any way to know which are the ntp servers being used by the Host, testing on the Host cli?

Best regards

Hi, you will need to make sure that you configure the chronyd in the container in the same way as the hostOS is.

The hostOS chronyd configuration is meta-balena/chrony.conf at master · balena-os/meta-balena · GitHub. As you see, four pools are defined by default.

Then the hostOS parses config.json to add user-configured entries in meta-balena/balena-ntp-config at master · balena-os/meta-balena · GitHub.

NTP servers can also be configured via DHCP - this is configured by NetworkManager in meta-balena/98dhcp_ntp at master · balena-os/meta-balena · GitHub.

I hope the above helps.

When you run the chronyd in the container, it will read the default NTP servers from its configuration file. Any other update you will have to update chrony sources manually.
The chronyd in the container will then keep the system time.

Hi @alexgg and @maggie0002

Thank you for your highly helpful inputs!
We are almost there and will follow this topic in the thread:

which seems more appropriate

Best regards