troglobit / finit

Fast init for Linux. Cookies included
https://troglobit.com/projects/finit/
MIT License
621 stars 61 forks source link

Set hostname as soon as possible #373

Closed liuming50 closed 8 months ago

liuming50 commented 9 months ago

We find it's useful to get know hostname before plugins get initialized, since some plugins might want to do some machine specific settings.

This change mainly aims to satisfy that requirement, to set hostname as soon as possible in main function.

troglobit commented 9 months ago

With the current state of Finit, this change mean we'd set hostname twice during bootstrap, with potentially different names since at the point of your change the file /etc/finit.conf has not yet been read.

liuming50 commented 8 months ago

With the current state of Finit, this change mean we'd set hostname twice during bootstrap, with potentially different names since at the point of your change the file /etc/finit.conf has not yet been read.

Yes, I am also aware of that, it will invalidate the DEFHOST or the setting from /etc/finit.conf, though it would not harm since at last the hostname would be set to /etc/hostname anyway if it exists.

Do you have any ideas about how to support this kind of requirement? Or do you think it's a valid requirement to allow hostname to be accessed during plugins initializing?

troglobit commented 8 months ago

Well, my gut reaction is to not accept this PR since I think we should not change hostname until we've had the chance to evaluate the configuration.

For one of my own use-cases our /etc is read-only in the boot image. We then apply an OverlayFS (tmpfs) so we can write/change files in /etc. As the last stage of bootstrap we generate /etc/hostname from a central file (startup-config -> NETCONF (sysrepo) => /etc/hostname). So for us this PR would mean potentially three changes at boot.

Also, I do not see why a plugin would want to (or need to) know the (potential) hostname this early. Why do you have this requirement, does your plugins extract a device role or something from the hostname, e.g. "door-controller1" or similar? Can't they read out that information from /etc/hostname themselves in that case?

Maybe unrelated, but worth mentioning since I've just made the change right before this last release candidate for v4.5. The native dbus plugin registers the dbus service with Finit early. This was a problem in one of our setups so I've added a "delayed" registration where plugins can ask Finit to generate a foo.conf that it loads after all critical services have been loaded. So dbus.so now creates /run/finit/system/dbus.conf, and if that service needed hostname it would be correctly set at that point in the execution. For more info, in case you're interested, see 5d703fd.

liuming50 commented 8 months ago

@troglobit thanks for the reply, that makes sense.

Yes, we could figure out another way to fix it in plugins, like reading /ect/hostname directly. I am closing this MR.