Skip to content

Instantly share code, notes, and snippets.

@pujianto
Last active June 8, 2017 12:10
Show Gist options
  • Save pujianto/90afa749422081f484b1eab0d3db28f0 to your computer and use it in GitHub Desktop.
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.
#!/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