summaryrefslogtreecommitdiff
path: root/cloudinit/config/cc_mounts.py
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit/config/cc_mounts.py')
-rw-r--r--cloudinit/config/cc_mounts.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/cloudinit/config/cc_mounts.py b/cloudinit/config/cc_mounts.py
index 0c3ce15e..33fe4ddc 100644
--- a/cloudinit/config/cc_mounts.py
+++ b/cloudinit/config/cc_mounts.py
@@ -201,6 +201,20 @@ def handle_swapcfg(swapcfg):
LOG.debug("no need to setup swap")
return
+ if os.path.exists(fname):
+ if not os.path.exists("/proc/swaps"):
+ LOG.debug("swap file %s existed. no /proc/swaps. Being safe.",
+ fname)
+ return
+ try:
+ for line in util.load_file("/proc/swaps").splitlines():
+ if line.startswith(fname + " "):
+ LOG.debug("swap file %s already used", fname)
+ return
+ except:
+ LOG.warn("swap file %s existed. Error reading /proc/swaps", fname)
+ return
+
try:
if isinstance(size, str) and size != "auto":
size = util.human2bytes(size)