From 8f4085caa97f76f8ae4c6e7b26b1d3165ea6e8c2 Mon Sep 17 00:00:00 2001 From: gau1991 Date: Fri, 26 Sep 2014 19:35:23 +0530 Subject: [PATCH] Improved Functions --- src/lib/ee_lib_create_swap.sh | 35 ++++++++++++++++++++--------------- src/lib/ee_lib_ram.sh | 3 ++- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/lib/ee_lib_create_swap.sh b/src/lib/ee_lib_create_swap.sh index 37cae5de..05cb98b8 100644 --- a/src/lib/ee_lib_create_swap.sh +++ b/src/lib/ee_lib_create_swap.sh @@ -2,22 +2,27 @@ function ee_lib_create_swap() { - # Use dd command to create SWAP - # Swap Parameters: - # Location: /swapfile - # Block Size: 1024 - dd if=/dev/zero of=/swapfile bs=1024 count=1024k &>> $EE_COMMAND_LOG \ - || ee_lib_error "Unable to generate /swapfile, exit status = " $? + if [ $EE_TOTAL_RAM -le 512 ]; then + if [ $EE_TOTAL_SWAP -le $EE_SWAP ];then - # Create it as a Swap - mkswap /swapfile &>> $EE_COMMAND_LOG \ - || ee_lib_error "Unable to create swapfile, exit status = " $? + # Use dd command to create SWAP + # Swap Parameters: + # Location: /swapfile + # Block Size: 1024 + dd if=/dev/zero of=/swapfile bs=1024 count=1024k &>> $EE_COMMAND_LOG \ + || ee_lib_error "Unable to generate /swapfile, exit status = " $? - # On the Swap - swapon /swapfile &>> $EE_COMMAND_LOG \ - || ee_lib_error "Unable to on Swap, exit status = " $? + # Create it as a Swap + mkswap /swapfile &>> $EE_COMMAND_LOG \ + || ee_lib_error "Unable to create swapfile, exit status = " $? - # Add entry into /etc/fstab - echo "/swapfile none swap sw 0 0" >> /etc/fstab \ - || ee_lib_error "Unable to add entry into /etc/fstab, exit status = " $? + # On the Swap + swapon /swapfile &>> $EE_COMMAND_LOG \ + || ee_lib_error "Unable to on Swap, exit status = " $? + + # Add entry into /etc/fstab + echo "/swapfile none swap sw 0 0" >> /etc/fstab \ + || ee_lib_error "Unable to add entry into /etc/fstab, exit status = " $? + fi + fi } diff --git a/src/lib/ee_lib_ram.sh b/src/lib/ee_lib_ram.sh index be49e400..cc9c9120 100644 --- a/src/lib/ee_lib_ram.sh +++ b/src/lib/ee_lib_ram.sh @@ -2,8 +2,9 @@ function ee_lib_ram() { - # Detect RAM of System + # Detect RAM and SWAP of System readonly EE_TOTAL_RAM=$(free -m | grep -i Mem | awk '{ print $2 }') + readonly EE_TOTAL_SWAP=$(free -m | grep -i Swap | awk '{ print $2 }') # RAM < 512MB if [ $EE_TOTAL_RAM -le 512 ]; then