/usr/local/etc/rc.syshook.d/carp
#!/usr/local/bin/php<?phprequire_once("config.inc");require_once("util.inc");require_once("interfaces.inc");$subsystem = !empty($argv[1]) ? $argv[1] : '';$type = !empty($argv[2]) ? $argv[2] : '';if ($subsystem != "1@igb0") exit;if (!in_array($type, ['MASTER', 'BACKUP'])) exit; switch ($type) { case 'MASTER': $config['OPNsense']['wireguard']['general']['enabled'] = '1'; write_config("Enable WireGuard due to CARP event on '{$subsystem}'", false); log_msg("Starting WireGuard due to CARP event '$type' on '{$subsystem}'"); break; case 'BACKUP': $config['OPNsense']['wireguard']['general']['enabled'] = '0'; write_config("Disable WireGuard due to CARP event on '{$subsystem}'", false); log_msg("Stopping WireGuard due to CARP event '$type' on '{$subsystem}'"); break; }use OPNsense\Core\Backend;$backend = new Backend();$backend->configdRun('template reload OPNsense/Wireguard'); $backend->configdpRun('wireguard configure');
#!/usr/local/bin/php<?phprequire_once("config.inc");require_once("util.inc");require_once("interfaces.inc");$subsystem = !empty($argv[1]) ? $argv[1] : '';$type = !empty($argv[2]) ? $argv[2] : '';if ($subsystem != "1@igb0") exit;if (!in_array($type, ['MASTER', 'BACKUP'])) exit; switch ($type) { case 'MASTER': shell_exec("/usr/local/sbin/pluginctl -s wireguard start"); log_msg("Starting WireGuard due to CARP event '$type' on '{$subsystem}'"); break; case 'BACKUP': shell_exec("/usr/local/sbin/pluginctl -s wireguard stop"); log_msg("Stopping WireGuard due to CARP event '$type' on '{$subsystem}'"); break; }
System > High Availability > Settings > WireGuard