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
+19
View File
@@ -11,6 +11,7 @@ const DefaultSystemdUnit = "uncloud-corrosion.service"
type SystemdService struct {
DataDir string
Unit string
running bool
}
func DefaultSystemdService(dataDir string) *SystemdService {
@@ -25,5 +26,23 @@ func (s *SystemdService) Start() error {
return fmt.Errorf("systemctl start %s: %w", s.Unit, err)
}
slog.Info("Corrosion systemd service started.", "unit", s.Unit)
// TODO: run a goroutine to check the status of the service and log any errors in the uncloud log.
s.running = true
return nil
}
func (s *SystemdService) Restart() error {
if _, err := exec.Command("systemctl", "restart", s.Unit).Output(); err != nil {
return fmt.Errorf("systemctl restart %s: %w", s.Unit, err)
}
slog.Info("Corrosion systemd service restarted.", "unit", s.Unit)
// TODO: run a goroutine to check the status of the service and log any errors in the uncloud log.
s.running = true
return nil
}
func (s *SystemdService) Running() bool {
return s.running
}