From 002cff65ee41d6bd87b230cb3f8f9a4822cd35ba Mon Sep 17 00:00:00 2001 From: Sheng Yang Date: Wed, 14 Sep 2011 02:58:45 -0700 Subject: [PATCH] bug 11351: Add parameters for binary file/log file --- .../config/etc/init.d/cloud-early-config | 26 +++++++++++-- .../debian/config/etc/init.d/postinit | 3 +- .../config/root/redundant_router/backup.sh | 20 ---------- .../root/redundant_router/backup.sh.templ | 20 ++++++++++ .../config/root/redundant_router/fault.sh | 17 --------- .../root/redundant_router/fault.sh.templ | 17 +++++++++ .../redundant_router/keepalived.conf.templ | 10 ++--- .../config/root/redundant_router/master.sh | 37 ------------------- .../root/redundant_router/master.sh.templ | 37 +++++++++++++++++++ ...mary-backup.sh => primary-backup.sh.templ} | 2 +- 10 files changed, 104 insertions(+), 85 deletions(-) delete mode 100644 patches/systemvm/debian/config/root/redundant_router/backup.sh create mode 100644 patches/systemvm/debian/config/root/redundant_router/backup.sh.templ delete mode 100644 patches/systemvm/debian/config/root/redundant_router/fault.sh create mode 100644 patches/systemvm/debian/config/root/redundant_router/fault.sh.templ delete mode 100644 patches/systemvm/debian/config/root/redundant_router/master.sh create mode 100644 patches/systemvm/debian/config/root/redundant_router/master.sh.templ rename patches/systemvm/debian/config/root/redundant_router/{primary-backup.sh => primary-backup.sh.templ} (98%) 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 af2ce4fcf1d..1306bfa2076 100755 --- a/patches/systemvm/debian/config/etc/init.d/cloud-early-config +++ b/patches/systemvm/debian/config/etc/init.d/cloud-early-config @@ -333,24 +333,42 @@ setup_apache2() { } setup_redundant_router() { + rrouter_bin_path="/root/redundant_router" + rrouter_log="/root/keepalived.log" + rrouter_bin_path_str="\/root\/redundant_router" + rrouter_log_str="\/root\/keepalived.log" rm /tmp/rrouter.lock ip route delete default cp /root/redundant_router/keepalived.conf.templ /etc/keepalived/keepalived.conf cp /root/redundant_router/conntrackd.conf.templ /etc/conntrackd/conntrackd.conf - cp /root/redundant_router/enable_pubip.sh.templ /root/redundant_router/enable_pubip.sh + cp /root/redundant_router/enable_pubip.sh.templ $rrouter_bin_path/enable_pubip.sh + cp /root/redundant_router/master.sh.templ $rrouter_bin_path/master.sh + cp /root/redundant_router/backup.sh.templ $rrouter_bin_path/backup.sh + cp /root/redundant_router/fault.sh.templ $rrouter_bin_path/fault.sh + cp /root/redundant_router/primary-backup.sh.templ $rrouter_bin_path/primary-backup.sh 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 sed -i "s/\[PRIORITY\]/$ROUTER_PR/g" /etc/keepalived/keepalived.conf + sed -i "s/\[RROUTER_BIN_PATH\]/$rrouter_bin_path_str/g" /etc/keepalived/keepalived.conf sed -i "s/\[DELTA\]/2/g" /etc/keepalived/keepalived.conf sed -i "s/\[LINK_IF\]/eth0/g" /etc/conntrackd/conntrackd.conf sed -i "s/\[LINK_IP\]/$ETH0_IP/g" /etc/conntrackd/conntrackd.conf sed -i "s/\[IGNORE_IP1\]/$GUEST_GW/g" /etc/conntrackd/conntrackd.conf sed -i "s/\[IGNORE_IP2\]/$ETH0_IP/g" /etc/conntrackd/conntrackd.conf sed -i "s/\[IGNORE_IP3\]/$ETH1_IP/g" /etc/conntrackd/conntrackd.conf - sed -i "s/\[ETH2IP\]/$ETH2_IP/g" /root/redundant_router/enable_pubip.sh - sed -i "s/\[ETH2MASK\]/$ETH2_MASK/g" /root/redundant_router/enable_pubip.sh - sed -i "s/\[GATEWAY\]/$GW/g" /root/redundant_router/enable_pubip.sh + sed -i "s/\[ETH2IP\]/$ETH2_IP/g" $rrouter_bin_path/enable_pubip.sh + sed -i "s/\[ETH2MASK\]/$ETH2_MASK/g" $rrouter_bin_path/enable_pubip.sh + sed -i "s/\[GATEWAY\]/$GW/g" $rrouter_bin_path/enable_pubip.sh + sed -i "s/\[RROUTER_BIN_PATH\]/$rrouter_bin_path_str/g" $rrouter_bin_path/master.sh + sed -i "s/\[RROUTER_BIN_PATH\]/$rrouter_bin_path_str/g" $rrouter_bin_path/backup.sh + sed -i "s/\[RROUTER_BIN_PATH\]/$rrouter_bin_path_str/g" $rrouter_bin_path/fault.sh + sed -i "s/\[RROUTER_LOG\]/$rrouter_log_str/g" $rrouter_bin_path/master.sh + sed -i "s/\[RROUTER_LOG\]/$rrouter_log_str/g" $rrouter_bin_path/backup.sh + sed -i "s/\[RROUTER_LOG\]/$rrouter_log_str/g" $rrouter_bin_path/fault.sh + sed -i "s/\[RROUTER_LOG\]/$rrouter_log_str/g" $rrouter_bin_path/primary-backup.sh + chmod a+x $rrouter_bin_path/*.sh + sed -i "s/--exec\ \$DAEMON;/--exec\ \$DAEMON\ --\ --vrrp;/g" /etc/init.d/keepalived grep "sleep 10;" /etc/init.d/keepalived > /dev/null if [ $? -ne 0 ] diff --git a/patches/systemvm/debian/config/etc/init.d/postinit b/patches/systemvm/debian/config/etc/init.d/postinit index b68c708229e..d052881a108 100755 --- a/patches/systemvm/debian/config/etc/init.d/postinit +++ b/patches/systemvm/debian/config/etc/init.d/postinit @@ -38,8 +38,9 @@ setup_redundant_router() { then return 1 fi + rrouter_bin_path="/root/redundant_router" eth2mac=`ip link show eth2 | awk '/ether/ {print $2}'` - sed -i "s/\[ETH2MAC\]/$eth2mac/g" /root/redundant_router/enable_pubip.sh + sed -i "s/\[ETH2MAC\]/$eth2mac/g" $rrouter_bin_path/enable_pubip.sh } start() { diff --git a/patches/systemvm/debian/config/root/redundant_router/backup.sh b/patches/systemvm/debian/config/root/redundant_router/backup.sh deleted file mode 100644 index 0ca4bc783a1..00000000000 --- a/patches/systemvm/debian/config/root/redundant_router/backup.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -source /root/func.sh - -lock="rrouter" -locked=$(getLockFile $lock) -if [ "$locked" != "1" ] -then - exit 1 -fi - -echo To backup called >> /root/keepalived.log -/root/redundant_router/disable_pubip.sh >> /root/keepalived.log 2>&1 -echo Disable public ip $? >> /root/keepalived.log -/root/redundant_router/primary-backup.sh backup >> /root/keepalived.log 2>&1 -echo Switch conntrackd mode backup $? >> /root/keepalived.log -echo Status: BACKUP >> /root/keepalived.log - -releaseLockFile $lock $locked -exit 0 diff --git a/patches/systemvm/debian/config/root/redundant_router/backup.sh.templ b/patches/systemvm/debian/config/root/redundant_router/backup.sh.templ new file mode 100644 index 00000000000..394e9a7aae2 --- /dev/null +++ b/patches/systemvm/debian/config/root/redundant_router/backup.sh.templ @@ -0,0 +1,20 @@ +#!/bin/bash + +source /root/func.sh + +lock="rrouter" +locked=$(getLockFile $lock) +if [ "$locked" != "1" ] +then + exit 1 +fi + +echo To backup called >> [RROUTER_LOG] +[RROUTER_BIN_PATH]/disable_pubip.sh >> [RROUTER_LOG] 2>&1 +echo Disable public ip $? >> [RROUTER_LOG] +[RROUTER_BIN_PATH]/primary-backup.sh backup >> [RROUTER_LOG] 2>&1 +echo Switch conntrackd mode backup $? >> [RROUTER_LOG] +echo Status: BACKUP >> [RROUTER_LOG] + +releaseLockFile $lock $locked +exit 0 diff --git a/patches/systemvm/debian/config/root/redundant_router/fault.sh b/patches/systemvm/debian/config/root/redundant_router/fault.sh deleted file mode 100644 index bf0b318e655..00000000000 --- a/patches/systemvm/debian/config/root/redundant_router/fault.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -source /root/func.sh - -lock="rrouter" -locked=$(getLockFile $lock) -if [ "$locked" != "1" ] -then - exit 1 -fi - -echo To fault called >> /root/keepalived.log -/root/redundant_router/disable_pubip.sh >> /root/keepalived.log 2>&1 -/root/redundant_router/primary-backup.sh fault >> /root/keepalived.log 2>&1 -echo Status: FAULT >> /root/keepalived.log - -releaseLockFile $lock $locked diff --git a/patches/systemvm/debian/config/root/redundant_router/fault.sh.templ b/patches/systemvm/debian/config/root/redundant_router/fault.sh.templ new file mode 100644 index 00000000000..c29dd3d7893 --- /dev/null +++ b/patches/systemvm/debian/config/root/redundant_router/fault.sh.templ @@ -0,0 +1,17 @@ +#!/bin/bash + +source /root/func.sh + +lock="rrouter" +locked=$(getLockFile $lock) +if [ "$locked" != "1" ] +then + exit 1 +fi + +echo To fault called >> [RROUTER_LOG] +[RROUTER_BIN_PATH]/disable_pubip.sh >> [RROUTER_LOG] 2>&1 +[RROUTER_BIN_PATH]/primary-backup.sh fault >> [RROUTER_LOG] 2>&1 +echo Status: FAULT >> [RROUTER_LOG] + +releaseLockFile $lock $locked diff --git a/patches/systemvm/debian/config/root/redundant_router/keepalived.conf.templ b/patches/systemvm/debian/config/root/redundant_router/keepalived.conf.templ index b7e11c18f04..2f400badf9f 100644 --- a/patches/systemvm/debian/config/root/redundant_router/keepalived.conf.templ +++ b/patches/systemvm/debian/config/root/redundant_router/keepalived.conf.templ @@ -5,7 +5,7 @@ global_defs { } vrrp_script check_bumpup { - script "/root/redundant_router/check_bumpup.sh" + script "[RROUTER_BIN_PATH]/check_bumpup.sh" interval 5 weight [DELTA] } @@ -38,11 +38,11 @@ vrrp_instance inside_network { # can be unquoted (if just filename) # or quoted (if has parameters) # to MASTER transition - notify_master "/root/redundant_router/master.sh" + notify_master "[RROUTER_BIN_PATH]/master.sh" # to BACKUP transition - notify_backup "/root/redundant_router/backup.sh" + notify_backup "[RROUTER_BIN_PATH]/backup.sh" # FAULT transition - notify_fault "/root/redundant_router/fault.sh" + notify_fault "[RROUTER_BIN_PATH]/fault.sh" # for ANY state transition. # "notify" script is called AFTER the @@ -54,5 +54,5 @@ vrrp_instance inside_network { # $2 = name of group or instance # $3 = target state of transition # ("MASTER"|"BACKUP"|"FAULT") - #notify /root/redundant_router/notify.sh + #notify [RROUTER_BIN_PATH]/notify.sh } diff --git a/patches/systemvm/debian/config/root/redundant_router/master.sh b/patches/systemvm/debian/config/root/redundant_router/master.sh deleted file mode 100644 index d529dcad84c..00000000000 --- a/patches/systemvm/debian/config/root/redundant_router/master.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash - -source /root/func.sh - -lock="rrouter" -locked=$(getLockFile $lock) -if [ "$locked" != "1" ] -then - exit 1 -fi - -echo To master called >> /root/keepalived.log -/root/redundant_router/enable_pubip.sh >> /root/keepalived.log 2>&1 -ret=$? -last_msg=`tail -n 1 /root/keepalived.log` -echo Enable public ip returned $ret >> /root/keepalived.log -if [ $ret -ne 0 ] -then - echo Fail to enable public ip! >> /root/keepalived.log - ifconfig eth2 down - service keepalived stop >> /root/keepalived.log 2>&1 - service conntrackd stop >> /root/keepalived.log 2>&1 - echo Status: FAULT \($last_msg\) >> /root/keepalived.log - releaseLockFile $lock $locked - exit -fi -/root/redundant_router/primary-backup.sh primary >> /root/keepalived.log 2>&1 -ret=$? -echo Switch conntrackd mode primary returned $ret >> /root/keepalived.log -if [ $ret -ne 0 ] -then - echo Fail to switch conntrackd mode, but try to continue working >> /root/keepalived.log -fi -echo Status: MASTER >> /root/keepalived.log - -releaseLockFile $lock $locked -exit 0 diff --git a/patches/systemvm/debian/config/root/redundant_router/master.sh.templ b/patches/systemvm/debian/config/root/redundant_router/master.sh.templ new file mode 100644 index 00000000000..c5515ea4f5c --- /dev/null +++ b/patches/systemvm/debian/config/root/redundant_router/master.sh.templ @@ -0,0 +1,37 @@ +#!/bin/bash + +source /root/func.sh + +lock="rrouter" +locked=$(getLockFile $lock) +if [ "$locked" != "1" ] +then + exit 1 +fi + +echo To master called >> [RROUTER_LOG] +[RROUTER_BIN_PATH]/enable_pubip.sh >> [RROUTER_LOG] 2>&1 +ret=$? +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] + ifconfig eth2 down + service keepalived stop >> [RROUTER_LOG] 2>&1 + service conntrackd stop >> [RROUTER_LOG] 2>&1 + echo Status: FAULT \($last_msg\) >> [RROUTER_LOG] + releaseLockFile $lock $locked + exit +fi +[RROUTER_BIN_PATH]/primary-backup.sh primary >> [RROUTER_LOG] 2>&1 +ret=$? +echo Switch conntrackd mode primary returned $ret >> [RROUTER_LOG] +if [ $ret -ne 0 ] +then + echo Fail to switch conntrackd mode, but try to continue working >> [RROUTER_LOG] +fi +echo Status: MASTER >> [RROUTER_LOG] + +releaseLockFile $lock $locked +exit 0 diff --git a/patches/systemvm/debian/config/root/redundant_router/primary-backup.sh b/patches/systemvm/debian/config/root/redundant_router/primary-backup.sh.templ similarity index 98% rename from patches/systemvm/debian/config/root/redundant_router/primary-backup.sh rename to patches/systemvm/debian/config/root/redundant_router/primary-backup.sh.templ index c53fe2e2a18..d6221d75926 100644 --- a/patches/systemvm/debian/config/root/redundant_router/primary-backup.sh +++ b/patches/systemvm/debian/config/root/redundant_router/primary-backup.sh.templ @@ -20,7 +20,7 @@ CONNTRACKD_BIN=/usr/sbin/conntrackd CONNTRACKD_LOCK=/var/lock/conntrack.lock CONNTRACKD_CONFIG=/etc/conntrackd/conntrackd.conf -CONNTRACKD_LOG=/root/keepalived.log +CONNTRACKD_LOG=[RROUTER_LOG] case "$1" in primary)