Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hostname setting #2

Closed
wants to merge 6 commits into from
Closed

Hostname setting #2

wants to merge 6 commits into from

Conversation

zmrow
Copy link
Owner

@zmrow zmrow commented Jul 2, 2021

Issue number:

Description of changes:
Previously, hostname was written directly to disk by netdog called by wicked early in boot. At this point in the boot sequence, the API server isn't up yet. Rather than rework the boot sequence and add the ability to netdog to talk to the API, we opted to add a subcommand to netdog as a settings generator for the new settings.network.hostname setting. The setting is used in a template file, which is an env file for a new systemd unit that calls netdog set-hostname. This command is what will write the hostname to disk at /proc/sys/kernel/hostname.

This means that at boot time, if a user has the hostname setting in their user data, we will use it, otherwise we will set the hostname, largely using the same logic as was in the program previously. (The only change is that if the DNS reverse lookup fails, we use the IP in the format "ip-x-x-x" as the hostname).

netdog was reworked to use argh for argument parsing since our custom logic was starting to get unwieldy with the addition of more subcommands with their own arguments.

Testing done:

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

This removes the custom argument parsing logic in favor of using `argh`.
`argh` makes it simpler to add additional subcommands that may or may
not have their own arguments.
This adds a new subcommand `generate-hostname` that is meant to be used
as a settings generator.  It will attempt to read the current IP from
file and resolve it via DNS reverse lookup.  If the lookup is successful
it is used, otherwise the IP is used with dots replaced by dashes to
avoid any confusion from other software that may attempt to read it, e.g
"1.2.3.4" will end up being hostname "ip-1-2-3-4".
This adds a new subcommand `set-hostname` that will write the given
hostname to disk.
This commit adds the ability to configure the hostname of the system via
a new setting `settings.network.hostname`.  If the setting isn't
populated, at boot time we use the settings generator `netdog
generate-hostname` to populate it.  The generator attempts to resolve
the current IP via reverse lookup, and if unsuccessful uses the IP to
create a hostname in the format "ip-x-x-x-x".

A new service `set-hostname` runs after `settings-applier` and writes
the hostname to `/proc/sys/kernel/hostname` via `netdog set-hostname
$HOSTNAME`.  The service unit file uses an env file that is a template
using the setting `settings.network.hostname` to populate the $HOSTNAME
variable.
This adds the migrations needed for `settings.network.hostname`, one for
the setting, its service and configuration file, and one for the setting
generator metadata.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant