Skip to content

Instantly share code, notes, and snippets.

@tranvictor
Created November 2, 2015 10:00
Show Gist options
  • Save tranvictor/8e0553de05590b63931f to your computer and use it in GitHub Desktop.
Save tranvictor/8e0553de05590b63931f to your computer and use it in GitHub Desktop.
Setup Ubuntu server, ready to deploy Rails application with Nginx, MongoDB, Redis
echo ">> Prepare"
ls /etc/apt/sources.list.d/ | grep mongodb
if [ $? -ne 0 ]; then
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
fi
echo ">> Updating System"
sudo apt-get update
# handle current bug in grub menu
sudo rm /boot/grub/menu.lst
sudo update-grub-legacy-ec2 -y
sudo apt-get dist-upgrade -qq --force-yes
# end handling
sudo apt-get -y upgrade
echo "Installing packages"
sudo apt-get -y install build-essential tcl8.5 imagemagick git-core nginx redis-server curl nodejs htop
echo ">> Installing MongoDB"
sudo apt-get install -y mongodb-org
echo ">> Installing rvm"
. $HOME/.rvm/scripts/rvm &> /dev/null
if [ $? -ne 0 ]
then
curl -L https://get.rvm.io | bash -s
source $HOME/.bash_profile
else
echo ">>> rvm already installed"
fi
cat $HOME/.bash_profile | grep RAILS_ENV
if [ $? -ne 0 ]
then
echo "export RAILS_ENV=production" >> $HOME/.bash_profile
fi
echo ">> Installing ruby version 2.2.1"
ruby -v &> /dev/null
if [ $? -ne 0 ]
then
rvm install 2.2.1
else
echo ">>> ruby 2.2.1 already installed"
fi
rvm --default use 2.2.1
ruby -v
echo ">> Installing Bundle"
BUNDLE="$(gem list bundle -i)"
if [ $BUNDLE = true ]; then
echo ">>> bundle is already installed"
else
gem install bundler -V --no-ri --no-rdoc
fi
echo ">> Setting up environment variables"
cat $HOME/.bashrc | grep "# Deployment variables"
if [ $? -ne 0 ]; then
VARIABLES="
# Deployment variables
export SECRET_KEY_BASE=<hidden>
export PAYPAL_LOGIN=<hidden>
export PAYPAL_PASSWORD=<hidden>
export PAYPAL_SIGNATURE=<hidden>
export MAILGUN_USERNAME=<hidden>
export MAILGUN_PASSWORD=<hidden>
export MAILGUN_DOMAIN_NAME=<hidden>
export API_ACCESS_KEY=<hidden>
export GITHUB_USER=<hidden>
export GITHUB_REPO=<hidden>
export GITHUB_OAUTH_TOKEN=<hidden>
export FACEBOOK_APP_ID=<hidden>
export FACEBOOK_APP_SECRET=<hidden>
export GOOGLE_CLIENT_ID=<hidden>
export GOOGLE_CLIENT_SECRET_KEY=<hidden>
export AWS_DEFAULT_REGION=<hidden>
export S3_BUCKET_NAME=<hidden>
export AWS_ACCESS_KEY_ID=<hidden>
export AWS_SECRET_ACCESS_KEY=<hidden>
"
echo "Prepend variable to .bashrc"
echo "$VARIABLES" >> /tmp/tempfile
cat $HOME/.bashrc >> /tmp/tempfile
mv /tmp/tempfile $HOME/.bashrc
source $HOME/.bashrc
else
echo ">>> environment variables are already set"
fi
echo ">> DONE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment