Last active
June 8, 2017 12:10
-
-
Save pujianto/90afa749422081f484b1eab0d3db28f0 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 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