start corrosion service even when machine is not initialised to be able to init cluster

This commit is contained in:
Pavel Sviderski
2024-10-01 15:04:20 +10:00
parent 6f9fc69c2e
commit 3287691a31
4 changed files with 60 additions and 6 deletions
+9 -2
View File
@@ -56,8 +56,15 @@ func (nc *networkController) Run(ctx context.Context) error {
}
slog.Info("WireGuard network configured.")
if err := nc.corroService.Start(); err != nil {
return err
if nc.corroService.Running() {
// Corrosion service was running before the WireGuard network was configured so we need to restart it.
if err := nc.corroService.Restart(); err != nil {
return fmt.Errorf("restart corrosion service: %w", err)
}
} else {
if err := nc.corroService.Start(); err != nil {
return fmt.Errorf("start corrosion service: %w", err)
}
}
// TODO: Figure out if we need to manually stop the corrosion service when the context is done or just
// rely on systemd to handle service dependencies on its own .