[PATCH] network-functions: add snapshot/rollback functions
by Dan Kenigsberg
When logging into a remote machine to play with its network
configurations there the fear of locking yourself out always lurks.
If this happens, you can walk to the remote machine and fix it, but it
would be easier to reboot the machine, and have it rolled back to a
known-good network configuration when it starts up.
With this patch, you can use snapshot_config() to copy the current
network configuration before changing it. The network service will use
rollback_config() when the machine is rebooted. Use commit_config() when
the current configuration is known to be good.
Comments are welcome. Specifically, what should we copy but ifcfg-* and
rule-* ?
---
rc.d/init.d/network | 6 ++++
sysconfig/network-scripts/network-functions | 41 +++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/rc.d/init.d/network b/rc.d/init.d/network
index 71e67ee..b789c31 100755
--- a/rc.d/init.d/network
+++ b/rc.d/init.d/network
@@ -44,6 +44,12 @@ cd /etc/sysconfig/network-scripts
. ./network-functions
+# when network starts afresh, roll back to last snapshot of network
+# configurations.
+if [ "$1" == start ]; then
+ rollback_config
+fi
+
# find all the interfaces besides loopback.
# ignore aliases, alternative configurations, and editor backup files
interfaces=$(ls ifcfg* | \
diff --git a/sysconfig/network-scripts/network-functions b/sysconfig/network-scripts/network-functions
index 89baeb4..6a1553e 100644
--- a/sysconfig/network-scripts/network-functions
+++ b/sysconfig/network-scripts/network-functions
@@ -361,3 +361,44 @@ change_resolv_conf ()
fi;
return $r;
}
+
+# take a snapshot of current network configuration scripts
+snapshot_config ()
+{
+ local snapshotdir
+ snapshotdir=/var/lib/initscripts/network-config
+ rm -fr "$snapshotdir"
+ mkdir -p "$snapshotdir"
+ for f in /etc/sysconfig/network-scripts/{ifcfg,rule}-*
+ do
+ [ -f "$f" ] && cp -p "$f" "$snapshotdir"
+ done
+}
+
+commit_config ()
+{
+ local snapshotdir
+ snapshotdir=/var/lib/initscripts/network-config
+ rm -fr "$snapshotdir"
+}
+
+# rollback network configuration to last snapshot (if one exists)
+rollback_config ()
+{
+ local snapshotdir rollbackdir
+ snapshotdir=/var/lib/initscripts/network-config
+ # return immediately if there is no snapshot
+ [ ! -d "$snapshotdir" ] && return 0
+
+ rollbackdir=/var/log/initscripts/rollback-`date +%Y.%m.%d-%H:%M:%S`
+ mkdir -p "$rollbackdir"
+ for f in /etc/sysconfig/network-scripts/{ifcfg,rule}-*
+ do
+ [ -f "$f" ] && mv "$f" "$rollbackdir"
+ done
+ for f in "$snapshotdir"/{ifcfg,rule}-*
+ do
+ [ -f "$f" ] && mv "$f" /etc/sysconfig/network-scripts
+ done
+}
+
--
1.6.6.1
14 years, 2 months
initscripts-9.06-1
by Bill Nottingham
Mainly, it's just a release that refreshes the master translation data.
Full log attached.
Bill
14 years, 2 months
[PATCH 00/11] Add NetworkManager integration to initscripts
by Bill Nottingham
Here's the first cut of NM integration into initscripts. It passes basic
testing.
Known issues:
- Bringing down of system connections that don't have DEVICE set in their
configuration does not work. I'm not seeing how to get this with nmcli
currently.
Please review, including checking for any misuses of the nmcli interface.
ifdown | 7 ++++++-
ifup | 11 ++++++++++-
ifup-eth | 2 +-
network-functions | 39 ++++++++++++++++++++++++++++++++++++---
4 files changed, 53 insertions(+), 6 deletions(-)
14 years, 2 months
initscripts 9.05 released
by Bill Nottingham
Two notable changes:
- We no longer use ethtool for checking link state; instead we rely on
/sys/class/net/$DEVICE/carrier. This should work on more devices, and
be simpler.
- In init.d/functions:daemon(), we now pass '-m' to runuser, to not clear
the environment. This matches the non-runuser case, allowing init scripts
to pass configuration.
And, as usual, assorted bugfixes. Full log attached.
Bill
14 years, 2 months