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