Skip to content

Instantly share code, notes, and snippets.

@moshest
Last active March 14, 2016 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moshest/06e3e03e0c0b0148b0ba to your computer and use it in GitHub Desktop.
Save moshest/06e3e03e0c0b0148b0ba to your computer and use it in GitHub Desktop.
Script for installing Node.js instance on Amazon AWS via user-data field & bitbucket.org
#!/usr/bin/env bash
set -e
NODE_ENV=production
GIT_HOSTNAME=bitbucket.org
GIT_PATH=username/project.git
GIT_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----"
INSTALL_SCRIPT=install.sh
RUN_SCRIPT=run.sh
RUN_USER=ec2-user
NODE_FOLDER=node
yum -y update
yum -y install git
su - $RUN_USER <<EOF
echo $GIT_PRIVATE_KEY > ~/.ssh/id_rsa
ssh-keyscan $GIT_HOSTNAME >> ~/.ssh/known_hosts
export NODE_ENV=$NODE_ENV
echo "export NODE_ENV=$NODE_ENV" >> ~/.bash_profile
cd ~/
git clone git@$GIT_HOSTNAME:$GIT_PATH $NODE_FOLDER
cd ~/$NODE_FOLDER
sh ./$INSTALL_SCRIPT
EOF
echo "su -l $RUN_USER -c \"cd ~/$NODE_FOLDER;sh ./$RUN_SCRIPT\"" >> /etc/rc.d/rc.local
su -l $RUN_USER -c "cd ~/$NODE_FOLDER;sh ./$RUN_SCRIPT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment