Launching a v4 Instance from the v4 AMI
- Select the nodestack-service-v4-QA or nodestack-service-v4-PROD AMI to launch
- m1.small (you might have to view ‘all generations’ to see it)
- launch into EC2-Classic (i.e. not in a VPC)
- set the IAM role: aws-nodestack-role (or else dynamo calls will fail!)
- choose EBS storage, 100G is plenty on the root and you don’t need additional stores
- Add these tags:
- Name => nodestack-service-v4-qa or nodestack-service-v4-prod
- ResourceGroup => nodestack-legacy
- Add these existing security groups:
- chef-nodes
- log-nodes
- ssh-access
- stats-node
- Use the magmic-aws-2012.pem file for access
- When the instance launches, ssh into it and update its nodestack-service git repository located at /srv/nodestack-service
- Use credentials for the automation user found in LastPass
cd /srv/nodestack-service sudo git pull
- Use credentials for the automation user found in LastPass
- Restart the nodestack service
sudo service nodestack restart - Add the instance to the correct ELB, either nodestack-qa or nodestack-prod
- Monitor the ELB, instances, and logs to ensure the service is operating properly
Launching a v4 Instance from Scratch
If launching from scratch, follow the same steps as above but select an Ubuntu 14.04 AMD 64 AMI. When it launches, run the following commands.
Installing Required Tools
sudo -s # keeps you in a root terminal
add-apt-repository ppa:nginx/stable # to get the latest stable nginx
apt-get update
apt-get install -y git nodejs npm libpq-dev nginx
You will also need to download a few setup files onto the machine to use in later commands. I recommend downloading the files to your machine and using scp to copy them to the home directory of your instance.
For example, for a qa instance:
scp -r -i /path/to/your/magmic-aws-2012.pem nodestack-service-v4-qa/qa/* ubuntu@<ip of your instance>:~/
Set up the Nodestack Server
mkdir /srv/nodestack-service
git clone https://magmic.git.beanstalkapp.com/nodestack-service.git /srv/nodestack-service/ # enter valid beanstalk credentials when prompted
# install the proper version of node and npm
npm install -g n
n 0.10.37
npm install -g npm@1.4.28
hash -r # needed so the system doesn't still use the old npm command version
cd /srv/nodestack-service
npm install # install everything for the v4 code
Now we can set up the node server as a service. All we need is to copy the nodestack.conf file from the setup package we put on the machine earlier to the right location.
cp ./nodestack.conf /etc/init/
mkdir -p /mnt/log/nodejs # make log location
service nodestack start
You can verify that the node server is running with this command:
$ curl localhost:3000
{"title":"Magmic Connected Services","subtitle":"Magmic Connected Services, version 2, 3 & 4"}
Now the machine is good to run a v4 server, but we also need to set up nginx for the url routing to work.
Configuring Nginx
There are handful of files from the setup package that need to be copied into the nginx configuration directory.
# first we remove the default config files
rm /etc/nginx/sites-available/default
rm /etc/nginx/sites-enabled/default
cp ./nginx/* /etc/nginx/sites-available/ # copy the proxy files over to sites-available
# enable them by making links in sites-enabled This for loop will make the links for everything in the sites-available folder
for file in `ls /etc/nginx/sites-available`; do ln -s /etc/nginx/sites-available/$file /etc/nginx/sites-enabled/; done
mkdir -p /mnt/log/nginx # make log location
service nginx restart # restart nginx
Now all that is left is to add your instance to the appropriate nodestack load balancer.
Troubleshooting
Check the logs on the instance with a command like this:
tail -f /mnt/log/nodejs/*.log
And if you need more logging, edit the /srv/nodestack-service/config/logger.js file and change it from INFO to DEBUG and restart the nodestack service. Just remember to set it back when you’re done!