in internal/system/swap.go [71:97]
func (s *swapAspect) swapOff() error {
swapfiles, err := getSwapfilePaths()
if err != nil {
return err
}
for _, swap := range swapfiles {
path := swap.filePath
if swap.swapType == swapTypePartition {
return fmt.Errorf("partition type swapfile %s found in /proc/swaps, please remove the swapfile", swap.filePath)
}
if _, err := os.Stat(path); err == nil {
s.logger.Info("Disabling swap...", zap.Reflect("swapfile path", path))
offCmd := exec.Command("swapoff", path)
out, err := offCmd.CombinedOutput()
if err != nil {
return fmt.Errorf("failed to turn of swap on %s, command output: %s, %v", path, out, err)
}
} else if errors.Is(err, fs.ErrNotExist) {
// path to swapfile does not exist
s.logger.Warn("swapfile path does not exists", zap.Reflect("swapfile path", path))
} else {
// file may or may not exist. See err for details.
return fmt.Errorf("unexpced error while trying to open /proc/swaps file: %v", err)
}
}
return nil
}