Last active
March 14, 2016 09:38
-
-
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
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
#!/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