cmd/cli: allow running upgrade while ctrld not installed

This commit is contained in:
Cuong Manh Le
2024-05-10 23:13:13 +07:00
committed by Cuong Manh Le
parent 0d6ca57536
commit 09936f1f07

View File

@@ -854,9 +854,9 @@ NOTE: Uninstalling will set DNS to values provided by DHCP.`,
mainLog.Load().Error().Msg(err.Error())
return
}
svcInstalled := true
if _, err := s.Status(); errors.Is(err, service.ErrNotInstalled) {
mainLog.Load().Warn().Msg("service not installed")
return
svcInstalled = false
}
bin, err := os.Executable()
if err != nil {
@@ -895,6 +895,9 @@ NOTE: Uninstalling will set DNS to values provided by DHCP.`,
}
doRestart := func() bool {
if !svcInstalled {
return true
}
tasks := []task{
{s.Stop, false},
{s.Start, false},
@@ -906,7 +909,9 @@ NOTE: Uninstalling will set DNS to values provided by DHCP.`,
}
return false
}
mainLog.Load().Debug().Msg("Restarting ctrld service using new binary")
if svcInstalled {
mainLog.Load().Debug().Msg("Restarting ctrld service using new binary")
}
if doRestart() {
_ = os.Remove(oldBin)
_ = os.Chmod(bin, 0755)