summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Hanreich <s.hanreich@proxmox.com>2025-07-16 15:08:00 +0200
committerThomas Lamprecht <t.lamprecht@proxmox.com>2025-07-17 00:10:35 +0200
commitccb1c8c122852992945b27b4fc8fa9ac75ee3a3a (patch)
tree585abf54cd5d6e47d1b9bd7ec45d2e3c4c886318
parentdc4e285c16a51d4317bde3c7cc47ab6b8582b9e6 (diff)
frr: add new helpers for reloading frr configuration
The reload and restart parts of the original reload_controller_config have been split into two functions, in order to make error handling in the new apply function easier. The new apply function tries to reload via frr-reload.py and if that fails, it falls back to restarting the frr service. Since frr-reload.py does *not* start / stop daemons that have been added / remove to /etc/frr/daemons, we add a new parameter that can be used to restart the frr service instead of just using frr-reload.py. Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com> Link: https://lore.proxmox.com/20250716130837.585796-40-g.goller@proxmox.com
-rw-r--r--src/PVE/Network/SDN/Frr.pm65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/PVE/Network/SDN/Frr.pm b/src/PVE/Network/SDN/Frr.pm
index 9c6e91c..2698928 100644
--- a/src/PVE/Network/SDN/Frr.pm
+++ b/src/PVE/Network/SDN/Frr.pm
@@ -44,6 +44,71 @@ sub read_local_frr_config {
}
}
+my $FRR_CONFIG_FILE = "/etc/frr/frr.conf";
+
+=head3 apply()
+
+Tries to reload FRR with the frr-reload.py script from frr-pythontools. If that
+isn't installed or doesn't work it falls back to restarting the systemd frr
+service. If C<$force_restart> is set, then the FRR daemon will be restarted,
+without trying to reload it first.
+
+=cut
+
+sub apply {
+ my ($force_restart) = @_;
+
+ if (!-e $FRR_CONFIG_FILE) {
+ log_warn("$FRR_CONFIG_FILE is not present.");
+ return;
+ }
+
+ run_command(['systemctl', 'enable', '--now', 'frr'])
+ if !-e "/etc/systemd/system/multi-user.target.wants/frr.service";
+
+ if (!$force_restart) {
+ eval { reload() };
+ return if !$@;
+
+ warn "reloading frr configuration failed: $@";
+ warn "trying to restart frr instead";
+ }
+
+ eval { restart() };
+ warn "restarting frr failed: $@" if $@;
+}
+
+sub reload {
+ my $bin_path = "/usr/lib/frr/frr-reload.py";
+
+ if (!-e $bin_path) {
+ die "missing $bin_path. Please install the frr-pythontools package";
+ }
+
+ my $err = sub {
+ my $line = shift;
+ warn "$line \n";
+ };
+
+ run_command([$bin_path, '--stdout', '--reload', $FRR_CONFIG_FILE], errfunc => $err);
+}
+
+sub restart {
+ # script invoked by the frr systemd service
+ my $bin_path = "/usr/lib/frr/frrinit.sh";
+
+ if (!-e $bin_path) {
+ die "missing $bin_path. Please install the frr package";
+ }
+
+ my $err = sub {
+ my $line = shift;
+ warn "$line \n";
+ };
+
+ run_command(['systemctl', 'restart', 'frr'], errfunc => $err);
+}
+
=head3 to_raw_config(\%frr_config)
Converts a given C<\%frr_config> to the raw config format.