-
Notifications
You must be signed in to change notification settings - Fork 3.8k
keepalived: Added track_script option to sync group and fixed print_track_script_indent #29027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
6f43925
6d48739
169fcb7
b956c7f
2983ba4
e527de8
4285957
8848d0b
70f77b5
c2efbec
74df60d
294f983
1ed1a07
d73d73b
d9773e8
ca3d0eb
597e31c
f6ea206
2294eaa
dd30c72
51940d0
3c4f35b
5bee3a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -75,9 +75,12 @@ config globals 'globals' | |||||
| # list route "route1" | ||||||
|
|
||||||
| #config vrrp_sync_group | ||||||
| # option name "VI_sync_group_1" | ||||||
| # list group "VI_1" | ||||||
| # list group "VI_2" | ||||||
| # option name "VI_sync_group_1" | ||||||
| # list group "VI_1" | ||||||
| # list group "VI_2" | ||||||
| # Note that priority will not work with vrrp_script | ||||||
| # when in sync group | ||||||
| # list track_script "vrrp_script1" | ||||||
|
Comment on lines
+79
to
+83
|
||||||
| # option smtp_alert "1" | ||||||
| # option global_tracking 1 | ||||||
|
|
||||||
|
|
@@ -101,6 +104,29 @@ config globals 'globals' | |||||
| # option value "<script-file2>" | ||||||
| # option weight "2" | ||||||
|
|
||||||
| #config bfd_instance | ||||||
| # option name "bfd_instance1" | ||||||
| # option neighbor_ip '192.168.10.1' | ||||||
| # option source_ip '192.168.20.1' | ||||||
| # option min_rx '300' | ||||||
| # option min_tx '300' | ||||||
| # option idle_tx "1000" | ||||||
| # option hoplimit '30' | ||||||
| # option max_hops '30' | ||||||
| # option weight '50' | ||||||
|
|
||||||
| #config peer | ||||||
| # option name 'peer1' | ||||||
| # option address '192.168.0.1' | ||||||
| # option min_ttl '1' | ||||||
| # option max_ttl '255 | ||||||
|
|
||||||
| #config peer | ||||||
| # option name 'peer2' | ||||||
| # option address '192.168.1.1' | ||||||
| # option min_ttl '1' | ||||||
| # option max_ttl '255 | ||||||
|
|
||||||
| #config vrrp_instance | ||||||
| # option name "VI_1" | ||||||
| # option use_vmac "eth0" | ||||||
|
|
@@ -112,14 +138,15 @@ config globals 'globals' | |||||
| # list track_script "track_script1" | ||||||
| # list track_script "track_script2" | ||||||
| # option dont_track_primary "1" | ||||||
| # list unicast_peer "192.168.0.1" | ||||||
| # list unicast_peer "192.168.1.1" | ||||||
| # list unicast_peer "peer1" | ||||||
| # list unicast_peer "peer2" | ||||||
| # list virtual_ipaddress "ipaddress2" | ||||||
| # list virtual_ipaddress "ipaddress3" | ||||||
| # list virtual_ipaddress_excluded "ipaddress4" | ||||||
| # list virtual_ipaddress_excluded "ipaddress5" | ||||||
| # list virtual_routes "route1" | ||||||
| # list virtual_routes "route2" | ||||||
| # list track_bfd "bfd_instance1" | ||||||
| # option mcast_src_ip "224.0.0.1" | ||||||
| # option unicast_src_ip "192.168.0.1" | ||||||
| # option virtual_router_id "128" | ||||||
|
|
@@ -132,11 +159,16 @@ config globals 'globals' | |||||
| # option accept "1" | ||||||
|
|
||||||
| #config vrrp_script | ||||||
| # option name "vrrp_script1" | ||||||
| # option script "<script-file>" | ||||||
| # option interval "5" | ||||||
| # weight will increase +10 if script status is OK, otherwise -10 | ||||||
| # option weight "10" | ||||||
| # option fall "2" | ||||||
| # option rise "3" | ||||||
| # valid values for direction reverse|noreverse -- reverse flips weight change | ||||||
| # option direction "reverse" | ||||||
| # option timeout "5" | ||||||
|
||||||
| # option timeout "5" | |
| # option timeout "5" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,13 +16,17 @@ INDENT_4="${INDENT_1}${INDENT_1}${INDENT_1}${INDENT_1}" | |
| config_section_open() { | ||
| local tag="$1" | ||
| local name="$2" | ||
| local indent="$3" | ||
|
|
||
| [ -n "$indent" ] && printf '%b' "$indent" >> "$KEEPALIVED_CONF" | ||
| printf '%s' "$tag" >> "$KEEPALIVED_CONF" | ||
| [ -n "$name" ] && printf ' %s' "$name" >> "$KEEPALIVED_CONF" | ||
| printf ' {\n' >> "$KEEPALIVED_CONF" | ||
| } | ||
|
|
||
| config_section_close() { | ||
| local indent="$1" | ||
| [ -n "$indent" ] && printf '%b' "$indent" >> "$KEEPALIVED_CONF" | ||
| printf '}\n\n' >> "$KEEPALIVED_CONF" | ||
| } | ||
|
|
||
|
|
@@ -215,16 +219,14 @@ print_track_script_indent() { | |
|
|
||
| local name value weight direction | ||
| config_get name "$section" name | ||
| [ "$name" != "$curr_track_elem" ] && return 0 | ||
| [ -z "$name" ] && return 0 | ||
|
|
||
| config_get value "$section" value | ||
| config_get weight "$section" weight | ||
|
Comment on lines
220
to
224
|
||
| config_get direction "$section" direction | ||
|
|
||
| [ -z "$value" ] && return 0 | ||
| [ "$direction" != "reverse" ] && [ "$direction" != "noreverse" ] && unset direction | ||
|
|
||
| printf '%b%s' "$indent" "$value" >> "$KEEPALIVED_CONF" | ||
| printf '%b%s' "$indent" "$name" >> "$KEEPALIVED_CONF" | ||
| [ -n "$weight" ] && printf ' weight %s' "$weight ${direction:+${direction}}" >> "$KEEPALIVED_CONF" | ||
| printf '\n' >> "$KEEPALIVED_CONF" | ||
| } | ||
|
|
@@ -268,15 +270,23 @@ print_unicast_peer_indent() { | |
| local section="$1" | ||
| local curr_track_elem="$2" | ||
| local indent="$3" | ||
| local name address | ||
| local name address max_ttl min_ttl | ||
|
|
||
| config_get name "$section" name | ||
| [ "$name" != "$curr_track_elem" ] && return 0 | ||
|
|
||
| config_get address "$section" address | ||
| [ -z "$address" ] && return 0 | ||
|
|
||
| printf '%b%s\n' "${indent}" "$address">> "$KEEPALIVED_CONF" | ||
| printf '%b%s' "${indent}" "$address" >> "$KEEPALIVED_CONF" | ||
|
|
||
| config_get min_ttl "$section" min_ttl | ||
| config_get max_ttl "$section" max_ttl | ||
|
|
||
| [ -n "$min_ttl" ] && printf ' min_ttl %s' "$min_ttl" >> "$KEEPALIVED_CONF" | ||
| [ -n "$max_ttl" ] && printf ' max_ttl %s' "$max_ttl" >> "$KEEPALIVED_CONF" | ||
| printf '\n' >> "$KEEPALIVED_CONF" | ||
|
|
||
| } | ||
|
|
||
| static_routes() { | ||
|
|
@@ -347,6 +357,17 @@ vrrp_sync_group() { | |
|
|
||
| print_elems_indent "$1" "$INDENT_1" no_val_smtp_alert no_val_global_tracking | ||
|
|
||
| # Handle track_script list for sync group | ||
| local track_script_val | ||
| config_get track_script_val "$1" track_script | ||
| if [ -n "$track_script_val" ]; then | ||
| config_section_open "track_script" "" "$INDENT_1" | ||
| for t in $track_script_val; do | ||
| config_foreach print_track_script_indent vrrp_script "$t" "$INDENT_2" | ||
| done | ||
| config_section_close "$INDENT_1" | ||
| fi | ||
|
|
||
| print_notify "GROUP" "$name" "$INDENT_1" notify_backup notify_master \ | ||
| notify_fault notify | ||
|
|
||
|
|
@@ -387,71 +408,71 @@ vrrp_instance() { | |
| config_get "$opt" "$1" "$opt" | ||
| eval optval=\$$opt | ||
| [ -z "$optval" ] && continue | ||
| printf '%b%s {\n' "${INDENT_1}" "$opt" >> "$KEEPALIVED_CONF" | ||
| config_section_open "$opt" "" "$INDENT_1" | ||
| for a in $optval; do | ||
| config_foreach print_ipaddress_indent ipaddress "$a" "$INDENT_2" | ||
| done | ||
| printf '%b}\n' "${INDENT_1}" >> "$KEEPALIVED_CONF" | ||
| config_section_close "$INDENT_1" | ||
| done | ||
|
|
||
| # Handle virtual_routes | ||
| for opt in virtual_routes; do | ||
| config_get "$opt" "$1" "$opt" | ||
| eval optval=\$$opt | ||
| [ -z "$optval" ] && continue | ||
| printf '%b%s {\n' "${INDENT_1}" "$opt" >> "$KEEPALIVED_CONF" | ||
| config_section_open "$opt" "" "$INDENT_1" | ||
| for r in $optval; do | ||
| config_foreach print_route_indent route "$r" "$INDENT_2" | ||
| done | ||
| printf '%b}\n' "${INDENT_1}" >> "$KEEPALIVED_CONF" | ||
| config_section_close "$INDENT_1" | ||
| done | ||
|
|
||
| # Handle track_script lists | ||
| for opt in track_script; do | ||
| config_get "$opt" "$1" "$opt" | ||
| eval optval=\$$opt | ||
| [ -z "$optval" ] && continue | ||
| printf '%b%s {\n' "${INDENT_1}" "$opt" >> "$KEEPALIVED_CONF" | ||
| config_section_open "$opt" "" "$INDENT_1" | ||
| for t in $optval; do | ||
| config_foreach print_track_script_indent track_script "$t" "$INDENT_2" | ||
| config_foreach print_track_script_indent vrrp_script "$t" "$INDENT_2" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see what you do, but can you please explain why this is needed?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently theres no support for track_script section, only for vrrp_script. I am not sure if this is how it was supposed to be done so correct me if I'm wrong but I tested this and it works.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As the old option is still valid, we need to extend it to include the new option too. What would a correct keepalived configuration look like if both the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The old option doesn't exist in the code. However its still present in the keepalived.config as of now. This is the sample configuration The above config generates this As you can see no section for
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But then I do not understand the uci why do i have to specifies the path to the script
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are absolutely right, we dont need the section track_script. On reviewing the docs of keepalived, a seprate track_script section doesnt exist. My guess is that it was removed and the config file was not updated, same with the init file. I think we should update
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hey do you need me to do something else?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make your suggested change.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all the suggest changes have been made. |
||
| done | ||
| printf '%b}\n' "${INDENT_1}" >> "$KEEPALIVED_CONF" | ||
| config_section_close "$INDENT_1" | ||
| done | ||
|
|
||
| # Handle track_interface lists | ||
| for opt in track_interface; do | ||
| config_get "$opt" "$1" "$opt" | ||
| eval optval=\$$opt | ||
| [ -z "$optval" ] && continue | ||
| printf '%b%s {\n' "${INDENT_1}" "$opt" >> "$KEEPALIVED_CONF" | ||
| config_section_open "$opt" "" "$INDENT_1" | ||
| for t in $optval; do | ||
| config_foreach print_track_elem_indent track_interface "$t" "$INDENT_2" | ||
| done | ||
| printf '%b}\n' "${INDENT_1}" >> "$KEEPALIVED_CONF" | ||
| config_section_close "$INDENT_1" | ||
| done | ||
|
|
||
| # Handle track_bfd lists | ||
| for opt in track_bfd; do | ||
| config_get "$opt" "$1" "$opt" | ||
| eval optval=\$$opt | ||
| [ -z "$optval" ] && continue | ||
| printf '%b%s {\n' "${INDENT_1}" "$opt" >> "$KEEPALIVED_CONF" | ||
| config_section_open "$opt" "" "$INDENT_1" | ||
| for t in $optval; do | ||
| config_foreach print_track_bfd_indent bfd_instance "$t" "$INDENT_2" | ||
| done | ||
| printf '%b}\n' "${INDENT_1}" >> "$KEEPALIVED_CONF" | ||
| config_section_close "$INDENT_1" | ||
| done | ||
|
|
||
| # Handle simple lists of strings (with no spaces in between) | ||
| for opt in unicast_peer; do | ||
| config_get "$opt" "$1" "$opt" | ||
| eval optval=\$$opt | ||
| [ -z "$optval" ] && continue | ||
| printf '%b%s {\n' "${INDENT_1}" "$opt" >> "$KEEPALIVED_CONF" | ||
| config_section_open "$opt" "" "$INDENT_1" | ||
| for t in $optval; do | ||
| config_foreach print_unicast_peer_indent peer "$t" "$INDENT_2" | ||
| done | ||
| printf '%b}\n' "${INDENT_1}" >> "$KEEPALIVED_CONF" | ||
| config_section_close "$INDENT_1" | ||
| done | ||
| unset optval | ||
|
|
||
|
|
@@ -466,7 +487,7 @@ vrrp_script() { | |
|
|
||
| config_section_open "vrrp_script" "$name" | ||
|
|
||
| print_elems_indent "$1" "$INDENT_1" script interval weight fall rise | ||
| print_elems_indent "$1" "$INDENT_1" script interval weight fall rise timeout | ||
|
|
||
| config_section_close | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes
are not needed leave it as it is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added some documentation for the new option here. Is the documentation not needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s fine that this is documented. But you’ve changed lines that you didn’t need to change.