Forked from pujianto/startup script on vultr: add 2GB of SWAP
Created
June 8, 2017 12:10
-
-
Save wsnjy/e33d9004dbc1b36c0a9e91bac9e524cc to your computer and use it in GitHub Desktop.
Simple startup script on instance creation on vultr.com, for this case only updating repo and adding swap.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#add swap | |
SWAP_SIZE="2G" | |
SWAP_MOUNT_NAME='/swapfile' | |
SWAP_EXISTS=`swapon -s` | |
SWAP_ON_STARTUP="$SWAP_MOUNT_NAME swap swap sw 0 0" | |
if [[ -z $SWAP_EXISTS ]] && [[ ! -f $SWAP_MOUNT_NAME ]] ; then | |
fallocate -l $SWAP_SIZE ${SWAP_MOUNT_NAME} | |
echo "allocating $SWAP_SIZE on $SWAP_MOUNT_NAME" | |
chmod 600 $SWAP_MOUNT_NAME | |
mkswap $SWAP_MOUNT_NAME | |
swapon -s | |
echo $SWAP_ON_STARTUP >> /etc/fstab | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment