rework NM-dispatcher/dhclient detection

The packaged NM dispatcher and dhclient scripts provide the same
functionality. Only one should be active depending on the system
configuration.

Instead of guessing in the NM dispatcher script whether the dhclient
script is executed, check in the dhclient script whether it is called
from a NM dispatcher script (the 11-dhclient script included in the
dhcp-client package).

This is simpler and it removes dependency on the 11-dhclient script.
This commit is contained in:
Miroslav Lichvar 2021-04-22 12:32:13 +02:00
parent c3c3f0c2dd
commit ba7e409249
3 changed files with 9 additions and 25 deletions

View File

@ -1,38 +1,17 @@
From 1b29e43133d992e735ffbf87d79f008994479036 Mon Sep 17 00:00:00 2001
From: Robert Fairley <rfairley@redhat.com>
Date: Wed, 17 Jun 2020 10:14:19 -0400
Subject: [PATCH] examples/nm-dispatcher.dhcp: use sysconfig, detect dhclient
Subject: [PATCH] examples/nm-dispatcher.dhcp: use sysconfig
Use the PEERNTP and NTPSERVERARGS environment variables from
/etc/sysconfig/network{-scripts}. Detect a dhclient install to avoid a
redundant operation with the 11-dhclient NM dispatcher in the
dhcp-client package.
/etc/sysconfig/network{-scripts}.
Co-Authored-By: Christian Glombek <cglombek@redhat.com>
---
examples/chrony.nm-dispatcher.dhcp | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/examples/chrony.nm-dispatcher.dhcp b/examples/chrony.nm-dispatcher.dhcp
index 6ea4c37..a6ad35a 100644
--- a/examples/chrony.nm-dispatcher.dhcp
+++ b/examples/chrony.nm-dispatcher.dhcp
@@ -6,21 +6,39 @@
export LC_ALL=C
+# If a dhclient installation is present, avoid a redundant operation
+# in case dhclient handles NTP server config through its own chrony config script,
+# exec'ed by NetworkManager's 11-dhclient dispatcher script.
+# In RHCOS, 11-dhclient is excluded and not shipped with base image.
+[ -e /usr/sbin/dhclient ] && \
+ [ -e /etc/dhcp/dhclient.d/chrony.sh ] && \
+ [ -e /etc/NetworkManager/dispatcher.d/11-dhclient -o \
+ -e /usr/lib/NetworkManager/dispatcher.d/11-dhclient ] && \
+ exit 0
+
interface=$1
action=$2
@@ -6,16 +6,24 @@
chronyc=/usr/bin/chronyc
default_server_options=iburst

View File

@ -4,6 +4,9 @@ CHRONY_SOURCEDIR=/run/chrony-dhcp
SERVERFILE=$CHRONY_SOURCEDIR/$interface.sources
chrony_config() {
# Disable modifications if called from a NM dispatcher script
[ -n "$NM_DISPATCHER_ACTION" ] && return 0
rm -f "$SERVERFILE"
if [ "$PEERNTP" != "no" ]; then
mkdir -p $CHRONY_SOURCEDIR
@ -15,6 +18,8 @@ chrony_config() {
}
chrony_restore() {
[ -n "$NM_DISPATCHER_ACTION" ] && return 0
if [ -f "$SERVERFILE" ]; then
rm -f "$SERVERFILE"
/usr/bin/chronyc reload sources > /dev/null 2>&1 || :

View File

@ -63,7 +63,7 @@ md5sum -c <<-EOF | (! grep -v 'OK$')
2d01b94bc1a7b7fb70cbee831488d121 examples/chrony.conf.example2
96999221eeef476bd49fe97b97503126 examples/chrony.keys.example
6a3178c4670de7de393d9365e2793740 examples/chrony.logrotate
2da011da89727ef009799502d84e7cd0 examples/chrony.nm-dispatcher.dhcp
a7054c9352c07384bd7ea0477e6e8a8c examples/chrony.nm-dispatcher.dhcp
8f5a98fcb400a482d355b929d04b5518 examples/chrony.nm-dispatcher.onoffline
32c34c995c59fd1c3ad1616d063ae4a0 examples/chronyd.service
EOF