diff options
author | Stefan Metzmacher <metze@samba.org> | 2010-02-09 16:34:59 +0100 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2010-02-23 10:38:49 +0100 |
commit | 3a0d830e4c991f545349823cb72941e28fcf8c8e (patch) | |
tree | d87680efd97d225020a2734821c4061440721c5f /ctdb/config | |
parent | 3419e9c4dd8f59865783e183ee2177870a776180 (diff) | |
download | samba-3a0d830e4c991f545349823cb72941e28fcf8c8e.tar.gz samba-3a0d830e4c991f545349823cb72941e28fcf8c8e.tar.xz samba-3a0d830e4c991f545349823cb72941e28fcf8c8e.zip |
config/13.per_ip_routing: add a setup_per_ip_routing() function
This combines the logic into a shell function which can be used by the
"takeip" and "updateip" hooks.
We check the return values of the "ip" commands now
instead of ignoring them.
We now create a setup_script.sh similar to the release_script.sh
which makes it easier to analyze problems.
metze
(This used to be ctdb commit 624e8878851b4957cc7c02e922ec86926d6927ee)
Diffstat (limited to 'ctdb/config')
-rwxr-xr-x | ctdb/config/events.d/13.per_ip_routing | 111 |
1 files changed, 61 insertions, 50 deletions
diff --git a/ctdb/config/events.d/13.per_ip_routing b/ctdb/config/events.d/13.per_ip_routing index a9fe6cf6d6..dc9ae2f29e 100755 --- a/ctdb/config/events.d/13.per_ip_routing +++ b/ctdb/config/events.d/13.per_ip_routing @@ -207,6 +207,7 @@ generate_per_ip_routing() table_id="" release_script="$_ipdir/release_script.sh" + setup_script="$_ipdir/setup_script.sh" test x"$_readonly" = x"yes" && { test -d $_ipdir || { @@ -227,12 +228,65 @@ generate_per_ip_routing() generate_auto_link_local $_ip $_maskbits } - release_script="$_ipdir/release_script.sh" run_release_script_once $release_script + echo -e "#!/bin/sh\n#\n" > $setup_script + chmod +x $setup_script + return 0; } +setup_per_ip_routing() +{ + local _ip=$1 + local _iface=$2 + local _table_id=$3 + local _release_script=$4 + local _setup_script=$5 + + local _config=`cat $CTDB_PER_IP_ROUTING_CONF` + local _lines=`echo -n "$_config" | grep -n "^$_ip " | cut -d ':' -f1 | xargs` + + local _pref="$CTDB_PER_IP_ROUTING_RULE_PREF" + + test -n "$_lines" && { + echo "ip rule del from $_ip pref $_pref table $_table_id" >> $_release_script + echo "ip route flush table $_table_id 2>/dev/null" >> $_release_script + + cmd="ip rule del from $_ip pref $_pref 2>/dev/null" + echo "$cmd" >> $_setup_script + + cmd="ip route flush table $_table_id 2>/dev/null" + echo "$cmd" >> $_setup_script + + cmd="ip rule add from $_ip pref $_pref table $_table_id" + echo "$cmd || {" >> $_setup_script + echo " echo \"$cmd - failed \$ret\"" >> $_setup_script + echo " exit \$ret" >> $_setup_script + echo "}" >> $_setup_script + } + local _l + for _l in $_lines; do + local _line=`echo -n "$_config" | head -n $_l | tail -n 1` + local _dest=`echo -n "$_line" | cut -d ' ' -f 2` + local _gw=`echo -n "$_line" | cut -d ' ' -f 3` + + local _via="" + test -n "$_gw" && { + _via="via $_gw" + } + + cmd="ip route add $_dest $_via dev $_iface table $_table_id" + echo "$cmd || {" >> $_setup_script + echo " echo \"$cmd - failed \$ret\"" >> $_setup_script + echo " exit \$ret" >> $_setup_script + echo "}" >> $_setup_script + done + + $_setup_script + return $?; +} + case "$1" in ############################# # called when ctdbd starts up @@ -298,31 +352,10 @@ case "$1" in exit 1; } - config=`cat $CTDB_PER_IP_ROUTING_CONF` - lines=`echo -n "$config" | grep -n "^$ip " | cut -d ':' -f1 | xargs` - - pref="$CTDB_PER_IP_ROUTING_RULE_PREF" - - test -n "$lines" && { - echo "ip rule del from $ip pref $pref table $table_id" >> $release_script - echo "ip route flush table $table_id 2>/dev/null" >> $release_script - - ip rule del from $ip pref $pref 2>/dev/null - ip rule add from $ip pref $pref table $table_id - ip route flush table $table_id 2>/dev/null + setup_per_ip_routing $ip $iface $table_id $release_script $setup_script || { + echo "$0: $1: setup_per_ip_routing $ip $iface $table_id $release_script $setup_script - failed" + exit 1; } - for l in $lines; do - line=`echo -n "$config" | head -n $l | tail -n 1` - dest=`echo -n "$line" | cut -d ' ' -f 2` - gw=`echo -n "$line" | cut -d ' ' -f 3` - - via="" - test -n "$gw" && { - via="via $gw" - } - - ip route add $dest $via dev $iface table $table_id - done # flush our route cache echo 1 > /proc/sys/net/ipv4/route/flush @@ -357,32 +390,10 @@ case "$1" in exit 1; } - config=`cat $CTDB_PER_IP_ROUTING_CONF` - lines=`echo -n "$config" | grep -n "^$ip " | cut -d ':' -f1 | xargs` - - pref="$CTDB_PER_IP_ROUTING_RULE_PREF" - - test -n "$lines" && { - echo "ip rule del from $ip pref $pref table $table_id" >> $release_script - echo "ip route flush table $table_id 2>/dev/null" >> $release_script - - ip rule del from $ip pref $pref 2>/dev/null - ip rule add from $ip pref $pref table $table_id - ip route flush table $table_id 2>/dev/null + setup_per_ip_routing $ip $niface $table_id $release_script $setup_script || { + echo "$0: $1: setup_per_ip_routing $ip $iface $table_id $release_script $setup_script - failed" + exit 1; } - for l in $lines; do - line=`echo -n "$config" | head -n $l | tail -n 1` - dest=`echo -n "$line" | cut -d ' ' -f 2` - gw=`echo -n "$line" | cut -d ' ' -f 3` - - via="" - test -n "$gw" && { - via="via $gw" - } - - ip route add $dest $via dev $niface table $table_id - done - # flush our route cache echo 1 > /proc/sys/net/ipv4/route/flush |