[prev in list] [next in list] [prev in thread] [next in thread] 

List:       initscripts-devel
Subject:    [PATCH] network-functions: add snapshot/rollback functions
From:       danken () redhat ! com (Dan Kenigsberg)
Date:       2010-02-28 16:57:16
Message-ID: 1267376236-12044-1-git-send-email-danken () redhat ! com
[Download RAW message or body]

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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic