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

fix: RHEL compatibility for systemd service ordering #100

Merged
merged 3 commits into from
Jun 7, 2023
Merged

fix: RHEL compatibility for systemd service ordering #100

merged 3 commits into from
Jun 7, 2023

Conversation

ThrRip
Copy link
Contributor

@ThrRip ThrRip commented Jun 7, 2023

On RHEL-based Linux distros, nss-lookup.target is deprecated and remains inactive (dead) forever by default.

$ systemctl status nss-lookup.target
○ nss-lookup.target - Host and Network Name Lookups
     Loaded: loaded (/usr/lib/systemd/system/nss-lookup.target; static)
     Active: inactive (dead)
       Docs: man:systemd.special(7)

This pull request replaces its usage in the service file with network-online.target, which is reached when the network is "up", and is also available on Debian-based distros. More information can be found at https://systemd.io/NETWORK_ONLINE/.

@layou233
Copy link
Owner

layou233 commented Jun 7, 2023

Thanks for your PR!

I searched for service files that included by popular projects, and I found sing-box and Xray are still using nss-lookup.target.

https://github.com/XTLS/Xray-install/blob/9af684cf00e129231e6861985f3c4b2ce67e2ffc/install-release.sh#L515

https://github.com/SagerNet/sing-box/blob/951d83cf9774e1ba785c90d36830d04c64942000/release/local/sing-box.service#L4

And in https://systemd.io/NETWORK_ONLINE/ they are also using nss-lookup.target in their FAQ.

Are they facing the same problem?

@ThrRip
Copy link
Contributor Author

ThrRip commented Jun 7, 2023

Are they facing the same problem?

Sometimes. nss-lookup.target still works as expected on Debian-based Linux distros (tested on Ubuntu 22.04 LTS), but not on RHEL-based distros anymore (tested on AlmaLinux 8 & 9).

In reality, network.target is reached when the system starts to bring the network up, and network-online.target when it finishes to do so. This operation takes a few seconds, while nss-lookup.target is reached somewhere in between them, when the hostname resolver becomes available.

Due to nss-lookup.target is inactive (again, only on RHEL-based distros), After=network.target nss-lookup.target will just start the service right after network.target is reached. If no network requests that requires access to addresses other than 127.0.0.1, 0.0.0.0, or :: are made in this short span, everything will be fine - and this is most of the cases.

So in conclusion, all these systemd service files, including the one in this project, they all work. Just might not be the most optimal ones, and make less sense.

@layou233
Copy link
Owner

layou233 commented Jun 7, 2023

Fair enough. BTW I asked ChatGPT for the support starting time in multiple distros:

Debian: network-online.target has been supported since Debian 9 "Stretch" (released in 2017) which includes systemd version 232.
Ubuntu: network-online.target has been supported since Ubuntu 17.10 "Artful Aardvark" (released in 2017) which includes systemd version 234.
OpenSUSE: network-online.target has been supported since at least version 13.2.
CentOS: network-online.target has been supported since CentOS 7 (released in 2014) which includes systemd version 219, but it was not enabled by default until later releases. In CentOS 7, you need to enable NetworkManager-wait-online.service to activate network-online.target
OpenWrt: network-online.target has been supported since OpenWrt 19.07 (released in 2019) which includes systemd version 241.

It looks like network-online.target has not been supported for a long time, should we add a comment in service file pointing to this issue to help users who uses extreme old Linux distros and faces some problem caused by this?

Although I don't think it's very likely that anyone would use this example service we provided LOL

@ThrRip
Copy link
Contributor Author

ThrRip commented Jun 7, 2023

I also asked Bing AI and Bard for this, and they're all giving answers that are different from each other's though. A comment is good to have.

Although I don't think it's very likely that anyone would use this example service we provided LOL

You got the point.

@layou233 layou233 merged commit a377910 into layou233:master Jun 7, 2023
@layou233
Copy link
Owner

layou233 commented Jun 7, 2023

Merged. Thanks again for your PR and your patience!

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.

2 participants