refactor corrosion into interface service

This commit is contained in:
Pavel Sviderski
2024-09-25 23:59:56 +10:00
parent 498d35e866
commit 2f7463ebe3
3 changed files with 53 additions and 2 deletions
+38
View File
@@ -0,0 +1,38 @@
package machine
import (
"fmt"
"log/slog"
"os/exec"
)
const (
CorrosionSystemdUnit = "uncloud-corrosion.service"
)
type CorrosionService interface {
Configure() error
Start() error
}
type CorrosionSystemdService struct {
Unit string
DataDir string
}
func (s *CorrosionSystemdService) Configure() error {
return nil
}
func (s *CorrosionSystemdService) Start() error {
unit := s.Unit
if unit == "" {
unit = CorrosionSystemdUnit
}
if _, err := exec.Command("systemctl", "start", unit).Output(); err != nil {
return fmt.Errorf("start %s: %w", unit, err)
}
slog.Info("Corrosion systemd service started.", "unit", unit)
return nil
}