Add swap precheck and clean jobs

Before create and add swap on system, check whether swapfile
is mounted. If so, try to swapoff the swapfile and remove it.

Change-Id: Ic3a9ffc34872a83a491412237369442f369c21d1
This commit is contained in:
Xingchao Yu 2017-04-12 19:22:02 +08:00
parent a8449161fa
commit fac24451af
1 changed files with 7 additions and 0 deletions

View File

@ -91,6 +91,13 @@ fi
if [ "${ADD_SWAP}" = true ]; then
print_header "Create $SWAP_SIZE_GB GB swapfile"
set +e
$SUDO swapon -s |grep -q '/swapfile'
RESULT=$?
set -e
if [ $RESULT -eq 0 ]; then
swapoff /swapfile && rm -f /swapfile
fi
$SUDO dd if=/dev/zero of=/swapfile count=${SWAP_SIZE_GB}k bs=1M
$SUDO chmod 0600 /swapfile
$SUDO mkswap /swapfile