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

Add localhost to /etc/hosts if not already present #779

Open
NiceGuyIT opened this issue Nov 5, 2021 · 5 comments
Open

Add localhost to /etc/hosts if not already present #779

NiceGuyIT opened this issue Nov 5, 2021 · 5 comments
Assignees
Labels
In Process To be fixed

Comments

@NiceGuyIT
Copy link
Contributor

Is your feature request related to a problem? Please describe.
I ran into an edge case where celery was taking significantly longer than normal due to localhost not resolving locally.

Describe the solution you'd like
I'd like for Tactical to be fast at all times and resolve localhost without making a network request.

Describe alternatives you've considered
This if more of a discussion about a strange edge case and possible documentation in case others run into the same problem. I've considered not opening this request and making note of it for future reference but that doesn't help the community.

Additional context
I installed Ubuntu 20.04 in an nspawn container with debootstrap and then installed Tactical using the standard install. One asset was added. Everything was working as expected. Then I introduced Nebula and in the process changed the DNS to use a server in the cloud. This caused significant delays in the frontend but technically everything still worked.

The troubleshooting process led to a celery being slow and timing celery shows about a 5 second delay. Compare the production timing with the dev timing.

Production

time /rmm/api/env/bin/celery -A tacticalrmm list bindings
Queue                        Exchange                     Routing Key
----------------             ----------------             ----------------
celery                       celery                       celery

real    0m0.337s
user    0m0.306s
sys     0m0.028s

Dev

time /rmm/api/env/bin/celery -A tacticalrmm list bindings
Queue                        Exchange                     Routing Key
----------------             ----------------             ----------------
celery                       celery                       celery

real    0m5.726s
user    0m0.321s
sys     0m0.039s

The output of time /rmm/api/env/bin/celery -A tacticalrmm report showed redis://localhost/ was used which clued me into localhost. This lead to the question: Where is localhost resolved? A fresh Ubuntu install creates /etc/hosts and adds the various localhost flavors for name resolution.

Fresh install of Ubuntu 20.04 in VM

127.0.0.1 localhost
127.0.1.1 $hostname

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Comparing a fresh Ubuntu 20.04 install with an nspawn install, /etc/hosts is missing from the nspawn install and present in the full install. /etc/nsswitch.conf is the same for host resolution: hosts: files dns. This leads us to DNS. Both systems have /etc/resolv.conf symlinked to /run/systemd/resolve/stub-resolv.conf which is provided by systemd-resolved.service. The change I made that broke celery was changing the symlink to /run/systemd/resolve/resolv.conf and adding a DNS=1.1.1.1 entry to /etc/systemd/resolved.conf, effectively removing systemd-resolved from the equation.

The systemd-resolved documentation states "systemd-resolved' will resolve synthetic records, one of which is localhost. If localhost is not in /etc/hosts and the DNS has not been changed, localhost will still resolve locally without making any DNS requests over the network. However, if localhost is not in /etc/hosts and the DNS has been changed, there will be significant delays in the frontend of Tactical.

Adding localhost to /etc/hosts if it's not already present doesn't introduce any problems because the installer adds them. I suggest checking for localhost and if it's not already present, add it to /etc/hosts.

@silversword411 silversword411 added the dev-triage Needs triaging by devs for issue assignment label Nov 6, 2021
@wh1te909
Copy link
Member

wh1te909 commented Nov 6, 2021

sounds good, the install script already adds entries to /etc/hosts so i'll also add localhost if not present

@silversword411 silversword411 added In Process To be fixed and removed dev-triage Needs triaging by devs for issue assignment labels Nov 7, 2021
@NiceGuyIT
Copy link
Contributor Author

For reference, here is /etc/hosts after a fresh install with hostname vs-23-ubuntu. I don't know if IPv6 is necessary if the application is not IPv6 aware.

127.0.0.1 localhost
127.0.1.1 vs-23-ubuntu

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Also /etc/os-release for version info.

NAME="Ubuntu"
VERSION="20.04.3 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.3 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

@silversword411 silversword411 added this to wh1te tasks in Ticket Triage Dec 24, 2021
@ninjamonkey198206
Copy link

If this still needs to be resolved, I could probably knock it out pretty quick. Should be the kind of grunt work I can currently handle while I'm learning the rest. Should just need the update and install scripts edited, unless I'm mistaken.

@ninjamonkey198206
Copy link

I'll add this in while I'm reworking the scripts. Planned to rework the host entries anyway.

@ninjamonkey198206
Copy link

@wh1te909 this has been added in the rework of the bash scripts I've been working on. Silver and Dinger are going to help test it all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Process To be fixed
Projects
Ticket Triage
wh1te tasks
Development

No branches or pull requests

4 participants