diff --git a/cmd/cli/commands_service.go b/cmd/cli/commands_service.go index 88ad552..6e57980 100644 --- a/cmd/cli/commands_service.go +++ b/cmd/cli/commands_service.go @@ -551,6 +551,18 @@ func (sc *ServiceCommand) Uninstall(cmd *cobra.Command, args []string) error { files = append(files, file) return nil }) + bin, err := os.Executable() + if err != nil { + mainLog.Load().Warn().Err(err).Msg("failed to get executable path") + } + if bin != "" && supportedSelfDelete { + files = append(files, bin) + } + // Backup file after upgrading. + oldBin := bin + oldBinSuffix + if _, err := os.Stat(oldBin); err == nil { + files = append(files, oldBin) + } for _, file := range files { if file == "" { continue @@ -559,6 +571,14 @@ func (sc *ServiceCommand) Uninstall(cmd *cobra.Command, args []string) error { mainLog.Load().Notice().Msgf("removed %s", file) } } + // Self-delete the ctrld binary if supported + if err := selfDeleteExe(); err != nil { + mainLog.Load().Warn().Err(err).Msg("failed to delete ctrld binary") + } else { + if !supportedSelfDelete { + mainLog.Load().Debug().Msgf("file removed: %s", bin) + } + } } return nil }