From a7a68de0df44d9de226163ccb16afd4d4f2e91fd Mon Sep 17 00:00:00 2001 From: Bertrand Gouny Date: Tue, 16 Jun 2015 13:07:17 +0200 Subject: [PATCH] add notify script --- CHANGELOG.md | 3 +++ image/env.yml | 2 ++ .../service/keepalived/assets/keepalived.conf | 2 ++ .../keepalived/assets/notify-example.sh | 20 +++++++++++++++++++ image/service/keepalived/container-start.sh | 9 +++++++++ 5 files changed, 36 insertions(+) create mode 100755 image/service/keepalived/assets/notify-example.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index ba10274..d7f44c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ # Changelog +## 0.1.1 + - Add notify script + ## 0.1.0 - Initial release diff --git a/image/env.yml b/image/env.yml index 3121883..8693efd 100644 --- a/image/env.yml +++ b/image/env.yml @@ -10,3 +10,5 @@ KEEPALIVED_UNICAST_PEERS: KEEPALIVED_VIRTUAL_IPS: - 192.168.1.231 + +KEEPALIVED_NOTIFY: /osixia/keepalived/notify-example.sh diff --git a/image/service/keepalived/assets/keepalived.conf b/image/service/keepalived/assets/keepalived.conf index e92f9d7..7425734 100644 --- a/image/service/keepalived/assets/keepalived.conf +++ b/image/service/keepalived/assets/keepalived.conf @@ -22,4 +22,6 @@ 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 new file mode 100755 index 0000000..f5a7fda --- /dev/null +++ b/image/service/keepalived/assets/notify-example.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +TYPE=$1 +NAME=$2 +STATE=$3 + +case $STATE in + "MASTER") echo "I'm the MASTER! Whup whup." + exit 0 + ;; + "BACKUP") "Ok, i'm just a backup, great." + exit 0 + ;; + "FAULT") echo "Fault, what ?" + exit 0 + ;; + *) echo "Unknown state" + exit 1 + ;; +esac diff --git a/image/service/keepalived/container-start.sh b/image/service/keepalived/container-start.sh index 9b58ce9..7da8a81 100755 --- a/image/service/keepalived/container-start.sh +++ b/image/service/keepalived/container-start.sh @@ -22,6 +22,12 @@ if [ ! -e "$FIRST_START_DONE" ]; then sed -i "s|{{ keepalived_priority }}|$KEEPALIVED_PRIORITY|g" /etc/keepalived/keepalived.conf 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 + else + sed -i "/{{ keepalived_notify }}/d" /etc/keepalived/keepalived.conf + fi + # unicast peers KEEPALIVED_UNICAST_PEERS=($KEEPALIVED_UNICAST_PEERS) for peer in "${KEEPALIVED_UNICAST_PEERS[@]}" @@ -53,6 +59,9 @@ if [ ! -e "$FIRST_START_DONE" ]; then sed -i "/{{ keepalived_virtual_ips }}/d" /etc/keepalived/keepalived.conf fi + cat /etc/keepalived/keepalived.conf + cat /osixia/keepalived/notify-example.sh + fi touch $FIRST_START_DONE