From 2df1fb5c42994bf326354a77d85a952a8d463af9 Mon Sep 17 00:00:00 2001 From: ofreax Date: Mon, 15 Jun 2015 21:33:06 +0200 Subject: [PATCH] init --- image/Dockerfile | 2 ++ image/env.yml | 9 +++------ image/service/keepalived/assets/keepalived.conf | 17 ++++++++++++----- image/service/keepalived/container-start.sh | 12 ++++++------ image/service/keepalived/daemon.sh | 2 +- 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/image/Dockerfile b/image/Dockerfile index eddab4d..ce13e35 100644 --- a/image/Dockerfile +++ b/image/Dockerfile @@ -6,6 +6,8 @@ MAINTAINER Bertrand Gouny # --net=host # -v /lib/modules:/lib/modules +# sudo docker run --privileged=true --net=host -v /lib/modules:/lib/modules -d osixia/keepalived:0.1.0 + # Use baseimage-docker's init system. CMD ["/sbin/my_init"] diff --git a/image/env.yml b/image/env.yml index f0a51cd..18420fd 100644 --- a/image/env.yml +++ b/image/env.yml @@ -1,4 +1,4 @@ -KEEPALIVED_INTERFACE: eno1 +KEEPALIVED_INTERFACE: wlan0 KEEPALIVED_PASSWORD: d0cker # for electing MASTER, highest priority wins. @@ -6,10 +6,7 @@ KEEPALIVED_PASSWORD: d0cker KEEPALIVED_PRIORITY: 150 KEEPALIVED_UNICAST_PEERS: - - 172.17.8.101 - - 172.17.8.102 - - 172.17.8.103 + - 192.168.1.9 KEEPALIVED_VIRTUAL_IPS: - - 192.168.200.17/24 dev eth1 - - 192.168.200.18/24 dev eth2 label eth2:1 + - 192.168.1.230 diff --git a/image/service/keepalived/assets/keepalived.conf b/image/service/keepalived/assets/keepalived.conf index 3f76140..552493d 100644 --- a/image/service/keepalived/assets/keepalived.conf +++ b/image/service/keepalived/assets/keepalived.conf @@ -1,19 +1,26 @@ -vrrp_instance VI_1 { +vrrp_instance vip-1 { interface {{ keepalived_interface }} + + track_interface { + {{ keepalived_interface }} + } + state MASTER virtual_router_id 51 priority {{ keepalived_priority }} + nopreempt - unicast_peer { - {{ peer_ip }} - } + unicast_peer {{ keepalived_unicast_peers }} virtual_ipaddress { - {{ floating_ip }} + {{ keepalived_virtual_ips }} } authentication { auth_type PASS auth_pass {{ keepalived_password }} } + + debug + } diff --git a/image/service/keepalived/container-start.sh b/image/service/keepalived/container-start.sh index ccc6ec5..9424cce 100755 --- a/image/service/keepalived/container-start.sh +++ b/image/service/keepalived/container-start.sh @@ -28,13 +28,13 @@ if [ ! -e "$FIRST_START_DONE" ]; then # it's just a peer # stored in a variable if [ -n "${!peer}" ]; then - sed -i "s|{{ peer_ip }}|${!peer}\n {{ peer_ip }}|g" /etc/keepalived/keepalived.conf + sed -i "s|{{ keepalived_unicast_peers }}|${!peer}\n {{ keepalived_unicast_peers }}|g" /etc/keepalived/keepalived.conf # directly else - sed -i "s|{{ peer_ip }}|${peer}\n {{ peer_ip }}|g" /etc/keepalived/keepalived.conf + sed -i "s|{{ keepalived_unicast_peers }}|${peer}\n {{ keepalived_unicast_peers }}|g" /etc/keepalived/keepalived.conf fi done - sed -i "/{{ peer_ip }}/d" /etc/keepalived/keepalived.conf + sed -i "/{{ keepalived_unicast_peers }}/d" /etc/keepalived/keepalived.conf # virtual ips KEEPALIVED_VIRTUAL_IPS=($KEEPALIVED_VIRTUAL_IPS) @@ -43,13 +43,13 @@ if [ ! -e "$FIRST_START_DONE" ]; then # it's just a peer # stored in a variable if [ -n "${!vip}" ]; then - sed -i "s|{{ floating_ip }}|${!vip}\n {{ floating_ip }}|g" /etc/keepalived/keepalived.conf + sed -i "s|{{ keepalived_virtual_ips }}|${!vip}\n {{ keepalived_virtual_ips }}|g" /etc/keepalived/keepalived.conf # directly else - sed -i "s|{{ floating_ip }}|${vip}\n {{ floating_ip }}|g" /etc/keepalived/keepalived.conf + sed -i "s|{{ keepalived_virtual_ips }}|${vip}\n {{ keepalived_virtual_ips }}|g" /etc/keepalived/keepalived.conf fi done - sed -i "/{{ floating_ip }}/d" /etc/keepalived/keepalived.conf + sed -i "/{{ keepalived_virtual_ips }}/d" /etc/keepalived/keepalived.conf fi fi diff --git a/image/service/keepalived/daemon.sh b/image/service/keepalived/daemon.sh index f4166ff..99921d8 100755 --- a/image/service/keepalived/daemon.sh +++ b/image/service/keepalived/daemon.sh @@ -1,2 +1,2 @@ #!/bin/bash -e -exec /usr/sbin/keepalived -f /etc/keepalived/keepalived.conf --dont-fork --log-console +exec /usr/sbin/keepalived -f /etc/keepalived/keepalived.conf --dont-fork --log-console -D -d