Skip to content

Commit

Permalink
Implement track_process (#278)
Browse files Browse the repository at this point in the history
Without this patch, a user is forced to use track_script with pgreps or kills to track process

This is not a problem in itself, but is error prone.

This patch fixes it by exposing in the role the track_process feature of keepalived.

The initial implementation was validating some of the track_process inputs directly in the role,
under the form of `param_match in ['initial', 'partial']`. 
Yet, this provides a different result (the incorrect data is silently not templated,
and no error is thrown) as a deployer would expect.

Instead, we rely on the fact that keepalived will throw a warning, and the user can
check it if necessary.
  • Loading branch information
zerwes authored May 19, 2023
1 parent 29f8985 commit a73191c
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions templates/keepalived.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,36 @@ vrrp_track_file {{ name }} {
{% endfor %}
{% endif %}

{% if keepalived_track_processs is defined %}
{% for name, details in keepalived_track_processs.items() %}
vrrp_track_process {{ name }} {
process {{ details.process }} # see man 5 keepalived.conf for quotes handling
weight {{ details.weight | default(1) | int }} # multiply with weight in process (default: 1, i.e. literal value from process)
{% if details.param_match is defined %}
param_match {{ details.param_match }}
{% endif %}
{% if details.quorum is defined %}
quorum {{ details.quorum | int }}
{% endif %}
{% if details.quorum_max is defined %}
quorum_max {{ details.quorum_max | int }}
{% endif %}
{% if details.fork_delay is defined %}
fork_delay {{ details.fork_delay | int }}
{% endif %}
{% if details.terminate_delay is defined %}
terminate_delay {{ details.terminate_delay | int }}
{% endif %}
{% if details.delay is defined %}
delay {{ details.delay | int }}
{% endif %}
{% if details.full_command | default(false) | bool %}
full_command
{% endif %}
}
{% endfor %}
{% endif %}

{% for name, sync_group in keepalived_sync_groups.items() %}
vrrp_sync_group {{ name }} {
group {
Expand Down Expand Up @@ -101,6 +131,13 @@ vrrp_sync_group {{ name }} {
{% endfor %}
}
{% endif %}
{% if sync_group.track_processs is defined %}
track_process {
{% for track_process in sync_group.track_processs %}
{{ track_process }}
{% endfor %}
}
{% endif %}
}
{% endfor %}

Expand Down Expand Up @@ -202,6 +239,13 @@ vrrp_instance {{ name }} {
{% endfor %}
}
{% endif %}
{% if instance.track_processs is defined %}
track_process {
{% for track_process in instance.track_processs %}
{{ track_process }}
{% endfor %}
}
{% endif %}

{% if instance.notify_script is defined %}
notify "{{ instance.notify_script }}"
Expand Down

0 comments on commit a73191c

Please sign in to comment.