diff --git a/cli/pkg/daemon/task.go b/cli/pkg/daemon/task.go index bfab84d11..85ecee96e 100644 --- a/cli/pkg/daemon/task.go +++ b/cli/pkg/daemon/task.go @@ -133,8 +133,11 @@ type DisableTerminusdService struct { } func (s *DisableTerminusdService) Execute(runtime connector.Runtime) error { - if _, err := runtime.GetRunner().SudoCmd("systemctl disable --now olaresd", false, true); err != nil { - return errors.Wrap(errors.WithStack(err), "disable olaresd failed") + stdout, _ := runtime.GetRunner().SudoCmd("systemctl is-active olaresd", false, false) + if stdout == "active" { + if _, err := runtime.GetRunner().SudoCmd("systemctl disable --now olaresd", false, true); err != nil { + return errors.Wrap(errors.WithStack(err), "disable olaresd failed") + } } return nil } @@ -144,10 +147,18 @@ type UninstallTerminusd struct { } func (r *UninstallTerminusd) Execute(runtime connector.Runtime) error { + var olaresdFiles []string svcpath := filepath.Join("/etc/systemd/system", templates.TerminusdService.Name()) svcenvpath := filepath.Join("/etc/systemd/system", templates.TerminusdEnv.Name()) - if _, err := runtime.GetRunner().SudoCmd(fmt.Sprintf("rm -rf %s && rm -rf %s && rm -rf /usr/local/bin/olaresd", svcpath, svcenvpath), false, false); err != nil { - return errors.Wrap(errors.WithStack(err), "remove olaresd failed") + binPath := "/usr/local/bin/olaresd" + olaresdFiles = append(olaresdFiles, svcpath, svcenvpath, binPath) + for _, pidFile := range []string{"installing.pid", "changingip.pid"} { + olaresdFiles = append(olaresdFiles, filepath.Join(runtime.GetBaseDir(), pidFile)) + } + for _, f := range olaresdFiles { + if _, err := runtime.GetRunner().SudoCmd(fmt.Sprintf("rm -rf %s", f), false, false); err != nil { + return errors.Wrap(errors.WithStack(err), "remove olaresd failed") + } } return nil } diff --git a/cli/pkg/phase/cluster/delete_cluster.go b/cli/pkg/phase/cluster/delete_cluster.go index 6f9a2357e..2dc663790 100644 --- a/cli/pkg/phase/cluster/delete_cluster.go +++ b/cli/pkg/phase/cluster/delete_cluster.go @@ -133,24 +133,13 @@ func (p *phaseBuilder) phasePrepare() *phaseBuilder { PhaseFile: common.TerminusStateFilePrepared, BaseDir: p.runtime.GetBaseDir(), }, + &daemon.UninstallTerminusdModule{}, &terminus.RemoveReleaseFileModule{}, ) } return p } -func (p *phaseBuilder) phaseDownload() *phaseBuilder { - terminusdAction := &daemon.CheckTerminusdService{} - err := terminusdAction.Execute() - - if p.convert() >= PhaseDownload { - if err == nil { - p.modules = append(p.modules, &daemon.UninstallTerminusdModule{}) - } - } - return p -} - func (p *phaseBuilder) phaseMacos() { p.modules = []module.Module{ &precheck.GreetingsModule{}, @@ -178,8 +167,7 @@ func UninstallTerminus(phase string, runtime *common.KubeRuntime) pipeline.Pipel builder. phaseInstall(). phaseStorage(). - phasePrepare(). - phaseDownload() + phasePrepare() } return pipeline.Pipeline{