diff --git a/README.md b/README.md index 52f7f0a..773839b 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,8 @@ See how to [set your own environment variables](#set-your-own-environment-variab - **KEEPALIVED_COMMAND_LINE_ARGUMENTS** Keepalived command line arguments; Defaults to `--log-detail --dump-conf` +- **KEEPALIVED_STATE** The starting state of keepalived; it can either be MASTER or BACKUP. + ### Set your own environment variables #### Use command line argument diff --git a/image/environment/default.yaml b/image/environment/default.yaml index 8d7f815..69d660c 100644 --- a/image/environment/default.yaml +++ b/image/environment/default.yaml @@ -18,3 +18,5 @@ KEEPALIVED_VIRTUAL_IPS: KEEPALIVED_NOTIFY: /container/service/keepalived/assets/notify.sh KEEPALIVED_ROUTER_ID: 51 + +KEEPALIVED_STATE: BACKUP diff --git a/image/service/keepalived/assets/keepalived.conf b/image/service/keepalived/assets/keepalived.conf index 2731659..af51c0f 100644 --- a/image/service/keepalived/assets/keepalived.conf +++ b/image/service/keepalived/assets/keepalived.conf @@ -5,7 +5,7 @@ global_defs { vrrp_instance VI_1 { interface {{ KEEPALIVED_INTERFACE }} - state BACKUP + state {{ KEEPALIVED_STATE }} virtual_router_id {{ KEEPALIVED_ROUTER_ID }} priority {{ KEEPALIVED_PRIORITY }} nopreempt diff --git a/image/service/keepalived/startup.sh b/image/service/keepalived/startup.sh index cf2b08a..5c077ca 100755 --- a/image/service/keepalived/startup.sh +++ b/image/service/keepalived/startup.sh @@ -11,6 +11,7 @@ if [ ! -e "$FIRST_START_DONE" ]; then # # bootstrap config # + sed -i "s|{{ KEEPALIVED_STATE }}|$KEEPALIVED_STATE|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf sed -i "s|{{ KEEPALIVED_ROUTER_ID }}|$KEEPALIVED_ROUTER_ID|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf sed -i "s|{{ KEEPALIVED_INTERFACE }}|$KEEPALIVED_INTERFACE|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf sed -i "s|{{ KEEPALIVED_PRIORITY }}|$KEEPALIVED_PRIORITY|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf