From 84c261f102d5d852dab9e169c1ba11d5aa35af3f Mon Sep 17 00:00:00 2001 From: Bertrand Gouny Date: Tue, 16 Jun 2015 14:06:49 +0200 Subject: [PATCH] add notify script --- .../service/keepalived/assets/keepalived.conf | 12 +++++++++--- .../keepalived/assets/notify-example.sh | 19 +++++++++++++++---- image/service/keepalived/container-start.sh | 5 +++-- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/image/service/keepalived/assets/keepalived.conf b/image/service/keepalived/assets/keepalived.conf index 7425734..91fc682 100644 --- a/image/service/keepalived/assets/keepalived.conf +++ b/image/service/keepalived/assets/keepalived.conf @@ -1,4 +1,12 @@ -vrrp_instance vip-1 { +vrrp_sync_group VG_1 { + group { + VI_1 + } + + {{ keepalived_notify }} +} + +vrrp_instance VI_1 { interface {{ keepalived_interface }} track_interface { @@ -22,6 +30,4 @@ vrrp_instance vip-1 { auth_type PASS auth_pass {{ keepalived_password }} } - - {{ keepalived_notify }} } diff --git a/image/service/keepalived/assets/notify-example.sh b/image/service/keepalived/assets/notify-example.sh index f5a7fda..37e5661 100755 --- a/image/service/keepalived/assets/notify-example.sh +++ b/image/service/keepalived/assets/notify-example.sh @@ -1,20 +1,31 @@ #!/bin/bash +# for ANY state transition. +# "notify" script is called AFTER the +# notify_* script(s) and is executed +# with 3 arguments provided by keepalived +# (ie don't include parameters in the notify line). +# arguments +# $1 = "GROUP"|"INSTANCE" +# $2 = name of group or instance +# $3 = target state of transition +# ("MASTER"|"BACKUP"|"FAULT") + TYPE=$1 NAME=$2 STATE=$3 case $STATE in - "MASTER") echo "I'm the MASTER! Whup whup." + "MASTER") echo "I'm the MASTER! Whup whup." >> keepalived.info exit 0 ;; - "BACKUP") "Ok, i'm just a backup, great." + "BACKUP") "Ok, i'm just a backup, great." >> keepalived.info exit 0 ;; - "FAULT") echo "Fault, what ?" + "FAULT") echo "Fault, what ?" >> keepalived.info exit 0 ;; - *) echo "Unknown state" + *) echo "Unknown state" >> keepalived.info exit 1 ;; esac diff --git a/image/service/keepalived/container-start.sh b/image/service/keepalived/container-start.sh index 7da8a81..7d21263 100755 --- a/image/service/keepalived/container-start.sh +++ b/image/service/keepalived/container-start.sh @@ -23,7 +23,8 @@ if [ ! -e "$FIRST_START_DONE" ]; then sed -i "s|{{ keepalived_password }}|$KEEPALIVED_PASSWORD|g" /etc/keepalived/keepalived.conf if [ -n "$KEEPALIVED_NOTIFY" ]; then - sed -i "s|{{ keepalived_notify }}|notify $KEEPALIVED_NOTIFY|g" /etc/keepalived/keepalived.conf + sed -i "s|{{ keepalived_notify }}|notify \"$KEEPALIVED_NOTIFY\"|g" /etc/keepalived/keepalived.conf + chmod 777 $KEEPALIVED_NOTIFY else sed -i "/{{ keepalived_notify }}/d" /etc/keepalived/keepalived.conf fi @@ -60,7 +61,7 @@ if [ ! -e "$FIRST_START_DONE" ]; then fi cat /etc/keepalived/keepalived.conf - cat /osixia/keepalived/notify-example.sh + cat $KEEPALIVED_NOTIFY fi