|
|
@ -2,7 +2,9 @@ |
|
|
|
from ee.core.variables import EEVariables |
|
|
|
from ee.core.shellexec import EEShellExec |
|
|
|
from ee.core.fileutils import EEFileUtils |
|
|
|
from ee.core.aptget import EEAptGet |
|
|
|
from ee.core.logging import Log |
|
|
|
import os |
|
|
|
|
|
|
|
|
|
|
|
class EESwap(): |
|
|
@ -17,12 +19,30 @@ class EESwap(): |
|
|
|
if EEVariables.ee_ram < 512: |
|
|
|
if EEVariables.ee_swap < 1000: |
|
|
|
Log.info(self, "Adding SWAP") |
|
|
|
EEShellExec.cmd_exec(self, "dd if=/dev/zero of=/ee-swapfile " |
|
|
|
"bs=1024 count=1048k") |
|
|
|
EEShellExec.cmd_exec(self, "mkswap /ee-swapfile") |
|
|
|
EEFileUtils.chown(self, "/ee-swapfile", "root", "root") |
|
|
|
EEFileUtils.chmod(self, "/ee-swapfile", 0o600) |
|
|
|
EEShellExec.cmd_exec(self, "swapon /ee-swapfile") |
|
|
|
with open("/etc/fstab", |
|
|
|
encoding='utf-8', mode='a') as swap_file: |
|
|
|
swap_file.write("/ee-swapfile\tnone\tswap\tsw\t0 0") |
|
|
|
|
|
|
|
# Install dphys-swapfile |
|
|
|
EEAptGet.update(self) |
|
|
|
EEAptGet.install(self, ["dphys-swapfile"]) |
|
|
|
# Stop service |
|
|
|
EEShellExec.cmd_exec(self, "service dphys-swapfile stop") |
|
|
|
# Remove Default swap created |
|
|
|
EEShellExec.cmd_exec(self, "/sbin/dphys-swapfile uninstall") |
|
|
|
|
|
|
|
# Modify Swap configuration |
|
|
|
if os.path.isfile("/etc/dphys-swapfile"): |
|
|
|
EEFileUtils.searchreplace(self, "/etc/dphys-swapfile", |
|
|
|
"#CONF_SWAPFILE=/var/swap", |
|
|
|
"CONF_SWAPFILE=/ee-swapfile") |
|
|
|
EEFileUtils.searchreplace(self, "/etc/dphys-swapfile", |
|
|
|
"#CONF_MAXSWAP=2048", |
|
|
|
"CONF_MAXSWAP=1024") |
|
|
|
EEFileUtils.searchreplace(self, "/etc/dphys-swapfile", |
|
|
|
"#CONF_SWAPSIZE=", |
|
|
|
"CONF_SWAPSIZE==1024") |
|
|
|
else: |
|
|
|
with open("/etc/dphys-swapfile", 'w') as conffile: |
|
|
|
conffile.write("CONF_SWAPFILE=/ee-swapfile\n" |
|
|
|
"CONF_SWAPSIZE=1024\n" |
|
|
|
"CONF_MAXSWAP=1024\n") |
|
|
|
# Create swap file |
|
|
|
EEShellExec.cmd_exec(self, "service dphys-swapfile start") |
|
|
|