Fix notify actions feature
diff --git a/README.rst b/README.rst
index f078f2b..249750e 100644
--- a/README.rst
+++ b/README.rst
@@ -77,20 +77,17 @@
instance:
VIP1:
nopreempt: True
- notify_action:
- master: |
- /usr/bin/docker start jenkins
- /usr/bin/docker start gerrit
- exit 0
- backup: |
- /usr/bin/docker stop jenkins
- /usr/bin/docker stop gerrit
- exit 0
- fault: |
- /usr/bin/docker stop jenkins
- /usr/bin/docker stop gerrit
- exit 0
- priority: 100 (highest priority must be on primary server, different for cluster members)
+ notify_action:
+ master:
+ - /usr/bin/docker start jenkins
+ - /usr/bin/docker start gerrit
+ backup:
+ - /usr/bin/docker stop jenkins
+ - /usr/bin/docker stop gerrit
+ fault:
+ - /usr/bin/docker stop jenkins
+ - /usr/bin/docker stop gerrit
+ priority: 100 # highest priority must be on primary server, different for cluster members
virtual_router_id: 51
password: pass
addresses:
diff --git a/keepalived/cluster.sls b/keepalived/cluster.sls
index cfcb536..a750bfa 100644
--- a/keepalived/cluster.sls
+++ b/keepalived/cluster.sls
@@ -20,12 +20,12 @@
keepalived_{{ instance_name }}_notify:
file.managed:
- - name: /usr/local/bin/keepalivednotify_{{ instance_name }}.sh
- - mode: 744
- - source: salt://keepalived/files/keepalivednotify.sh
+ - name: /usr/local/bin/keepalived_notify_{{ instance_name }}.sh
+ - mode: 755
+ - source: salt://keepalived/files/keepalived_notify.sh
- template: jinja
- defaults:
- instance_name: {{ instance_name }}
+ notify_action: {{ instance.notify_action }}
- require:
- pkg: keepalived_packages
- require_in:
diff --git a/keepalived/files/keepalived.conf b/keepalived/files/keepalived.conf
index b00925b..66b5b8c 100644
--- a/keepalived/files/keepalived.conf
+++ b/keepalived/files/keepalived.conf
@@ -14,7 +14,7 @@
state MASTER
{%- endif %}
{%- if instance.notify_action is defined %}
- notify /usr/local/bin/keepalivednotify_{{ instance_name }}.sh
+ notify /usr/local/bin/keepalived_notify_{{ instance_name }}.sh
{%- endif %}
interface {{ instance.interface }}
virtual_router_id {{ instance.virtual_router_id }}
diff --git a/keepalived/files/keepalived_notify.sh b/keepalived/files/keepalived_notify.sh
new file mode 100644
index 0000000..9fe6fe9
--- /dev/null
+++ b/keepalived/files/keepalived_notify.sh
@@ -0,0 +1,27 @@
+#!/bin/bash -e
+
+TYPE=$1
+NAME=$2
+STATE=$3
+
+case $STATE in
+ "MASTER")
+ {%- for action in notify_action.master %}
+ {{ action }}
+ {%- endfor %}
+ ;;
+ "BACKUP")
+ {%- for action in notify_action.backup %}
+ {{ action }}
+ {%- endfor %}
+ ;;
+ "FAULT")
+ {%- for action in notify_action.fault %}
+ {{ action }}
+ {%- endfor %}
+ ;;
+ *)
+ echo "Unknown state $STATE" 1>&2
+ exit 1
+ ;;
+esac
diff --git a/keepalived/files/keepalivednotify.sh b/keepalived/files/keepalivednotify.sh
deleted file mode 100644
index 2fa7055..0000000
--- a/keepalived/files/keepalivednotify.sh
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/bash
-{%- set instance = salt['pillar.get']('keepalived:server:instance:'+instance_name) %}
-
-TYPE=$1
-NAME=$2
-STATE=$3
-
-case $STATE in
- "MASTER") {{ instance.notify_action.master|indent(19, false) }}
- ;;
- "BACKUP") {{ instance.notify_action.backup|indent(19, false) }}
- ;;
- "FAULT") {{ instance.notify_action.fault|indent(19, false) }}
- ;;
- *) echo "unknown state"
- exit 1
- ;;
-esac
\ No newline at end of file