From a7a68de0df44d9de226163ccb16afd4d4f2e91fd Mon Sep 17 00:00:00 2001 From: Bertrand Gouny Date: Tue, 16 Jun 2015 13:07:17 +0200 Subject: [PATCH 2/5] 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 From 84c261f102d5d852dab9e169c1ba11d5aa35af3f Mon Sep 17 00:00:00 2001 From: Bertrand Gouny Date: Tue, 16 Jun 2015 14:06:49 +0200 Subject: [PATCH 3/5] 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 From 00a82790682ef3d7d6d282712e307e9d6b4d8499 Mon Sep 17 00:00:00 2001 From: Bertrand Gouny Date: Tue, 16 Jun 2015 14:09:20 +0200 Subject: [PATCH 4/5] add notify script --- image/service/keepalived/container-start.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/image/service/keepalived/container-start.sh b/image/service/keepalived/container-start.sh index 7d21263..e84d7de 100755 --- a/image/service/keepalived/container-start.sh +++ b/image/service/keepalived/container-start.sh @@ -24,7 +24,6 @@ if [ ! -e "$FIRST_START_DONE" ]; then if [ -n "$KEEPALIVED_NOTIFY" ]; then 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,9 +59,6 @@ if [ ! -e "$FIRST_START_DONE" ]; then sed -i "/{{ keepalived_virtual_ips }}/d" /etc/keepalived/keepalived.conf fi - cat /etc/keepalived/keepalived.conf - cat $KEEPALIVED_NOTIFY - fi touch $FIRST_START_DONE From d3c3df6c6623f9fcc922861179aff29eb0f5d639 Mon Sep 17 00:00:00 2001 From: ofreax Date: Sun, 21 Jun 2015 21:32:28 +0200 Subject: [PATCH 5/5] add notify script --- Makefile | 2 +- README.md | 2 +- image/env.yml | 6 ++++-- .../keepalived/assets/{notify-example.sh => notify.sh} | 8 ++++---- 4 files changed, 10 insertions(+), 8 deletions(-) rename image/service/keepalived/assets/{notify-example.sh => notify.sh} (69%) diff --git a/Makefile b/Makefile index e6b8112..e43ec87 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ NAME = osixia/keepalived -VERSION = 0.1.0 +VERSION = 0.1.1 .PHONY: all build test tag_latest release diff --git a/README.md b/README.md index 08206ae..11b8cfe 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,6 @@ A docker image to run Keepalived. ## Quick start -This image need to be run with : --privileged --net=host +This image require the kernel module ip_vs loaded on the host and need to be run with : --privileged --net=host docker run --privileged --net=host -d osixia/keepalived diff --git a/image/env.yml b/image/env.yml index 8693efd..ac615c3 100644 --- a/image/env.yml +++ b/image/env.yml @@ -1,4 +1,4 @@ -KEEPALIVED_INTERFACE: p4p1 +KEEPALIVED_INTERFACE: eth0 KEEPALIVED_PASSWORD: d0cker # for electing MASTER, highest priority wins. @@ -7,8 +7,10 @@ KEEPALIVED_PRIORITY: 150 KEEPALIVED_UNICAST_PEERS: - 192.168.1.10 + - 192.168.1.11 KEEPALIVED_VIRTUAL_IPS: - 192.168.1.231 + - 192.168.1.232 -KEEPALIVED_NOTIFY: /osixia/keepalived/notify-example.sh +KEEPALIVED_NOTIFY: /osixia/keepalived/notify.sh diff --git a/image/service/keepalived/assets/notify-example.sh b/image/service/keepalived/assets/notify.sh similarity index 69% rename from image/service/keepalived/assets/notify-example.sh rename to image/service/keepalived/assets/notify.sh index 37e5661..348de0f 100755 --- a/image/service/keepalived/assets/notify-example.sh +++ b/image/service/keepalived/assets/notify.sh @@ -16,16 +16,16 @@ NAME=$2 STATE=$3 case $STATE in - "MASTER") echo "I'm the MASTER! Whup whup." >> keepalived.info + "MASTER") logger "I'm the MASTER! Whup whup." exit 0 ;; - "BACKUP") "Ok, i'm just a backup, great." >> keepalived.info + "BACKUP") logger "Ok, i'm just a backup, great." exit 0 ;; - "FAULT") echo "Fault, what ?" >> keepalived.info + "FAULT") logger "Fault, what ?" exit 0 ;; - *) echo "Unknown state" >> keepalived.info + *) logger "Unknown state" exit 1 ;; esac