Last active
August 29, 2015 14:00
-
-
Save pmanijak/6cd72c7815e0ea1ab74e to your computer and use it in GitHub Desktop.
Circle Blvd server setup on Ubuntu 14 on Amazon: http://circleblvd.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
#!upstart | |
# | |
# Copy this to /etc/init/circle-blvd.conf | |
# Modified from https://www.exratione.com | |
# | |
description "Circle Blvd project management server" | |
start on startup | |
stop on shutdown | |
respawn | |
# This line is needed so that Upstart reports the pid of the Node.js process | |
# started by Forever rather than Forever's pid. | |
expect fork | |
env NODE_BIN_DIR="/usr/local/bin" | |
env NODE_PATH="/usr/local/lib/node_modules" | |
env APPLICATION_DIRECTORY="/home/ubuntu/apps/circle-blvd" | |
env APPLICATION_START="server.js" | |
env LOG="/var/log/circle-blvd.log" | |
env AS_USER="start-stop-daemon --start -c ubuntu --exec" | |
pre-start script | |
# Redirect port 80 requests to port 3000 | |
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000 | |
# Redirect port 443 requests to port 4000 | |
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 4000 | |
# Give us permission to access the logs | |
[ ! -f $LOG ] && { touch $LOG; } | |
chown ubuntu:ubuntu $LOG | |
end script | |
script | |
# Add the node executables to the path, which includes Forever if it is | |
# installed globally, which it should be. | |
PATH=$NODE_BIN_DIR:$PATH | |
# The minUptime and spinSleepTime settings stop Forever from thrashing if | |
# the application fails immediately on launch. This is generally necessary to | |
# avoid loading development servers to the point of failure every time | |
# someone makes an error in application initialization code, or bringing down | |
# production servers the same way if a database or other critical service | |
# suddenly becomes inaccessible. | |
# | |
# The w and watchDirectory options allows us to restart the app after | |
# there have been changes. | |
exec $AS_USER /usr/local/bin/forever -- --sourceDir $APPLICATION_DIRECTORY -a -l $LOG \ | |
--minUptime 5000 --spinSleepTime 2000 \ | |
-w --watchDirectory $APPLICATION_DIRECTORY start $APPLICATION_START | |
end script | |
pre-stop script | |
# Add the node executables to the path. | |
PATH=$NODE_BIN_DIR:$PATH | |
# Here we're using the pre-stop script to stop the Node.js application | |
# process so that Forever is given a chance to do its thing and tidy up | |
# its data. Note that doing it this way means that each application that | |
# runs under Forever must have a different start file name, regardless of | |
# which directory it is in. | |
exec $AS_USER /usr/local/bin/forever -- stop $APPLICATION_START >> $LOG | |
end script | |
post-stop script | |
# Revert iptables rules | |
iptables -t nat -D PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000 | |
iptables -t nat -D PREROUTING -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 4000 | |
end script |
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
These are instructions for setting up Circle Blvd on an Amazon EC2 instance running Ubuntu, | |
or really any Ubuntu server you are happy with. | |
It assumes the default user account is 'ubuntu' (created by the AMI). | |
Directions: | |
0. Create an EC2 instance using Amazon Web Services | |
--> AMI: Ubuntu Server 14 (free tier) | |
--> Security group: Add HTTP, HTTPS, and SSH rules | |
--> ssh into it with your key pair | |
1. Copy circle-blvd.conf to /etc/init/circle-blvd.conf | |
2. Copy setup.sh to ~/setup.sh | |
3. sh ./setup.sh | |
4. Agree to some things. | |
5. sudo start circle-blvd | |
5. That's it! | |
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
# prepare for couchdb | |
sudo apt-get install python-software-properties -y | |
sudo add-apt-repository ppa:couchdb/stable -y | |
sudo apt-get update -y | |
# remove any existing couchdb binaries | |
sudo apt-get remove couchdb couchdb-bin couchdb-common -yf | |
# install latest | |
sudo apt-get install -V couchdb | |
# install helpful things | |
sudo apt-get install git -y | |
sudo apt-get install nodejs -y | |
sudo apt-get install npm -y | |
sudo npm install -g forever | |
# nodejs -> node | |
sudo ln -s /usr/bin/nodejs /usr/local/bin/node | |
# get the app | |
cd | |
mkdir repos && cd repos | |
git clone https://github.com/secret-project/circle-blvd | |
cd circle-blvd/app/ | |
sudo npm install --production | |
# put the app in the deploy folder | |
cd | |
mkdir -p apps/circle-blvd | |
cp -R repos/circle-blvd/app/* apps/circle-blvd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment