Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/etc/rc.syshook.d/monitor/20-recover
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,23 @@ $affected_gateways = !empty($argv[1]) ? explode(',', $argv[1]) : [];

$metered_found_prios = ['inet' => 256, 'inet6' => 256];
$metered_gws = ['inet' => [], 'inet6' => []];
$all_statuses = return_gateways_status();
$has_viable_target = !empty(array_filter($all_statuses, function ($s) { return strpos($s['status'], 'down') === false; }));

foreach (return_gateways_status() as $status) {
foreach ($all_statuses as $status) {
if (strpos($status['status'], 'down') !== false) {
/* recover monitors stuck in down state ignoring "force_down" */
if ($status['status'] == 'down') {
$gwnames[] = $status['name'];
}
/* kill states for all down transitions including "force_down" */
if (!empty($status['monitor_killstates']) && in_array($status['name'], $affected_gateways)) {
$uuid = trim(configdp_run('filter kill gateway_states', [$status['gateway']], true));
log_msg("ROUTING: killing states for unreachable gateway {$status['name']} [$uuid]", LOG_NOTICE);
if ($has_viable_target) {
$uuid = trim(configdp_run('filter kill gateway_states', [$status['gateway']], true));
log_msg("ROUTING: killing states for unreachable gateway {$status['name']} [$uuid]", LOG_NOTICE);
} else {
log_msg("ROUTING: preserving states for {$status['name']} (no viable failover target)", LOG_NOTICE);
}
}
} else {
/* collect "metered" gateways for all non-down status reports */
Expand Down