From 5eba48919869720f98c1f4912de9d3686b092f49 Mon Sep 17 00:00:00 2001 From: Sheng Yang Date: Tue, 13 Nov 2012 19:03:36 -0800 Subject: [PATCH] Redundant Router: Restart vpn related services when redundant router fail-over --- .../config/etc/init.d/cloud-early-config | 1 + .../root/redundant_router/disable_pubip.sh | 2 - .../redundant_router/enable_pubip.sh.templ | 4 +- .../root/redundant_router/master.sh.templ | 6 ++ .../config/root/redundant_router/services.sh | 62 +++++++++++++++++++ 5 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 patches/systemvm/debian/config/root/redundant_router/services.sh diff --git a/patches/systemvm/debian/config/etc/init.d/cloud-early-config b/patches/systemvm/debian/config/etc/init.d/cloud-early-config index 64459fd6118..fe536cbb5a9 100755 --- a/patches/systemvm/debian/config/etc/init.d/cloud-early-config +++ b/patches/systemvm/debian/config/etc/init.d/cloud-early-config @@ -477,6 +477,7 @@ setup_redundant_router() { cp /root/redundant_router/check_bumpup.sh $rrouter_bin_path/ cp /root/redundant_router/disable_pubip.sh $rrouter_bin_path/ cp /root/redundant_router/checkrouter.sh.templ /opt/cloud/bin/checkrouter.sh + cp /root/redundant_router/services.sh $rrouter_bin_path/ sed -i "s/\[ROUTER_ID\]/$NAME/g" /etc/keepalived/keepalived.conf sed -i "s/\[ROUTER_IP\]/$GUEST_GW\/$GUEST_CIDR_SIZE/g" /etc/keepalived/keepalived.conf sed -i "s/\[BOARDCAST\]/$GUEST_BRD/g" /etc/keepalived/keepalived.conf diff --git a/patches/systemvm/debian/config/root/redundant_router/disable_pubip.sh b/patches/systemvm/debian/config/root/redundant_router/disable_pubip.sh index af5edbfd2a1..ee4e894ba69 100644 --- a/patches/systemvm/debian/config/root/redundant_router/disable_pubip.sh +++ b/patches/systemvm/debian/config/root/redundant_router/disable_pubip.sh @@ -21,5 +21,3 @@ while read i do ifconfig $i down done < /tmp/iflist -service cloud-passwd-srvr stop -service dnsmasq stop diff --git a/patches/systemvm/debian/config/root/redundant_router/enable_pubip.sh.templ b/patches/systemvm/debian/config/root/redundant_router/enable_pubip.sh.templ index ccdef0b7ea6..0e42ec4968a 100644 --- a/patches/systemvm/debian/config/root/redundant_router/enable_pubip.sh.templ +++ b/patches/systemvm/debian/config/root/redundant_router/enable_pubip.sh.templ @@ -30,6 +30,4 @@ do ifconfig $i up fi done < /tmp/iflist -ip route add default via [GATEWAY] dev eth2 && \ -service cloud-passwd-srvr restart && \ -service dnsmasq restart +ip route add default via [GATEWAY] dev eth2 diff --git a/patches/systemvm/debian/config/root/redundant_router/master.sh.templ b/patches/systemvm/debian/config/root/redundant_router/master.sh.templ index 418fd5d83b8..11ca6284f65 100644 --- a/patches/systemvm/debian/config/root/redundant_router/master.sh.templ +++ b/patches/systemvm/debian/config/root/redundant_router/master.sh.templ @@ -28,12 +28,18 @@ fi echo To master called >> [RROUTER_LOG] [RROUTER_BIN_PATH]/enable_pubip.sh >> [RROUTER_LOG] 2>&1 ret=$? +if [ $ret -eq 0 ] +then + [RROUTER_BIN_PATH]/services.sh restart >> [RROUTER_LOG] 2>&1 + ret=$? +fi last_msg=`tail -n 1 [RROUTER_LOG]` echo Enable public ip returned $ret >> [RROUTER_LOG] if [ $ret -ne 0 ] then echo Fail to enable public ip! >> [RROUTER_LOG] [RROUTER_BIN_PATH]/disable_pubip.sh >> [RROUTER_LOG] 2>&1 + [RROUTER_BIN_PATH]/services.sh stop >> [RROUTER_LOG] 2>&1 service keepalived stop >> [RROUTER_LOG] 2>&1 service conntrackd stop >> [RROUTER_LOG] 2>&1 echo Status: FAULT \($last_msg\) >> [RROUTER_LOG] diff --git a/patches/systemvm/debian/config/root/redundant_router/services.sh b/patches/systemvm/debian/config/root/redundant_router/services.sh new file mode 100644 index 00000000000..4d8949bcc00 --- /dev/null +++ b/patches/systemvm/debian/config/root/redundant_router/services.sh @@ -0,0 +1,62 @@ +#!/bin/bash +# Copyright 2012 Citrix Systems, Inc. Licensed under the +# Apache License, Version 2.0 (the "License"); you may not use this +# file except in compliance with the License. Citrix Systems, Inc. +# reserves all rights not expressly granted by the License. +# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +vpn_service() { + ps aux|grep ipsec | grep -v grep > /dev/null + no_vpn=$? + if [ $no_vpn -eq 1 ] + then + return 0 + fi + r=0 + case "$1" in + stop) + service ipsec stop && \ + service xl2tpd stop + r=$? + ;; + restart) + service ipsec restart && \ + service xl2tpd restart + r=$? + ;; + esac + return $r +} + +ret=0 +case "$1" in + start) + vpn_service restart && \ + service cloud-passwd-srvr start && \ + service dnsmasq start + ret=$? + ;; + stop) + vpn_service stop && \ + service cloud-passwd-srvr stop && \ + service dnsmasq stop + ret=$? + ;; + restart) + vpn_service restart && \ + service cloud-passwd-srvr restart && \ + service dnsmasq restart + ret=$? + ;; + *) + echo "Usage: services {start|stop|restart}" + exit 1 + ;; +esac + +exit $ret