~hacktivista/scripts

aeaabedbef36b0d42bb019c771a619a932f6ebc5 — Felix Freeman 1 year, 7 months ago 6707633 main
add path to linode-cli
1 files changed, 8 insertions(+), 8 deletions(-)

M dynfail
M dynfail => dynfail +8 -8
@@ 4,11 4,11 @@
#
# Calls to this script should be made on crontab
# on primary host:
# */1 * * * * . $HOME/.profile; dynfail failover
# */5 * * * * . $HOME/.profile; dynfail sync_ip
# */1 * * * * . $HOME/.profile; $HOME/.local/bin/dynfail failover
# */5 * * * * . $HOME/.profile; $HOME/.local/bin/dynfail sync_ip
# on secondary host:
# */1 * * * * . $HOME/.profile; dynfail recover
# */5 * * * * . $HOME/.profile; dynfail sync_ip
# */1 * * * * . $HOME/.profile; dynfail $HOME/.local/bin/recover
# */5 * * * * . $HOME/.profile; dynfail $HOME/.local/bin/sync_ip
#
# Requirements:
# - sudo with access to the postgres user


@@ 40,16 40,16 @@ databases=$DYNFAIL_DATABASES # string list divided by space

update_root_ip () {
    target_ip=$(dig -4 +short "$1")
    linode-cli domains records-update "$domain_id" "$root_record_id" \
        --target "$target_ip"
    $HOME/.local/bin/linode-cli domains records-update "$domain_id" \
        "$root_record_id" --target "$target_ip"
}

sync_ip () {
    last_ip=$(dig -4 +short "$this_host")
    current_ip="$(dig -4 +short myip.opendns.com @resolver1.opendns.com)"
    if [ "$last_ip" != "$current_ip" ]; then
        linode-cli domains records-update "$domain_id" "$this_record_id" \
            --target="$current_ip"
        $HOME/.local/bin/linode-cli domains records-update "$domain_id" \
            "$this_record_id" --target="$current_ip"
        update_root_ip "$this_host"
    fi
}