-
-
Save donpark/572292 to your computer and use it in GitHub Desktop.
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
load 'deploy' if respond_to?(:namespace) # cap2 differentiator | |
################################## | |
# Edit these | |
set :application, "stoned" | |
set :node_file, "app.js" | |
set :host, "ec2-204-236-143-54.us-west-1.compute.amazonaws.com" | |
ssh_options[:keys] = [File.join(ENV["HOME"], ".ec2", "default.pem")] | |
set :repository, "git://gist.github.com/572292.git" | |
set :branch, "master" | |
set :deploy_to, "/opt/#{application}" | |
#################################### | |
set :scm, :git | |
set :deploy_via, :remote_cache | |
role :app, host | |
set :user, "ubuntu" | |
set :use_sudo, true | |
set :admin_runner, 'node_js' | |
default_run_options[:pty] = true | |
namespace :deploy do | |
task :start, :roles => :app, :except => { :no_release => true } do | |
run "#{try_sudo :as => 'root'} start #{application}" | |
end | |
task :stop, :roles => :app, :except => { :no_release => true } do | |
run "#{try_sudo :as => 'root'} stop #{application}" | |
end | |
task :restart, :roles => :app, :except => { :no_release => true } do | |
run "#{try_sudo :as => 'root'} restart #{application} || #{try_sudo :as => 'root'} start #{application}" | |
end | |
task :create_deploy_to_with_sudo, :roles => :app do | |
run "#{try_sudo :as => 'root'} mkdir -p #{deploy_to}" | |
run "#{try_sudo :as => 'root'} chown #{admin_runner}:#{admin_runner} #{deploy_to}" | |
end | |
task :write_upstart_script, :roles => :app do | |
upstart_script = <<-UPSTART | |
description "#{application}" | |
start on startup | |
stop on shutdown | |
script | |
# We found $HOME is needed. Without it, we ran into problems | |
export HOME="/home/#{admin_runner}" | |
cd #{current_path} | |
exec sudo -u #{admin_runner} sh -c "/usr/local/bin/node #{current_path}/#{node_file} >> #{shared_path}/log/#{application}.log 2>&1" | |
end script | |
respawn | |
UPSTART | |
put upstart_script, "/tmp/#{application}_upstart.conf" | |
run "#{try_sudo :as => 'root'} mv /tmp/#{application}_upstart.conf /etc/init/#{application}.conf" | |
end | |
end | |
before 'deploy:setup', 'deploy:create_deploy_to_with_sudo' | |
after 'deploy:setup', 'deploy:write_upstart_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
#!/bin/bash | |
NODE_VERSION=0.2.0 | |
NODE_FILE=node-v$NODE_VERSION | |
apt-get update -y | |
apt-get install -y build-essential git-core | |
apt-get install -y libssl-dev pkg-config | |
apt-get install -y nginx | |
wget http://nodejs.org/dist/$NODE_FILE.tar.gz | |
tar -zxvf $NODE_FILE.tar.gz | |
pushd $NODE_FILE | |
./configure | |
make | |
make install | |
popd | |
rm $NODE_FILE.tar.gz | |
rm -rf $NODE_FILE | |
#make clean | |
sudo adduser \ | |
--system \ | |
--shell /bin/bash \ | |
--gecos 'User for running node.js projects' \ | |
--group \ | |
--disabled-password \ | |
--home /home/node \ | |
node_js | |
# Add ubuntu user to the node_js group | |
/usr/sbin/usermod -a -G node_js ubuntu | |
# Setup basic nginx proxy. | |
unlink /etc/nginx/sites-available/default | |
cat > /etc/nginx/sites-available/node_proxy.conf <<EOF | |
server { | |
listen 80; | |
# proxy to node | |
location / { | |
proxy_pass http://127.0.0.1:8000/; | |
} | |
} | |
EOF | |
ln -s /etc/nginx/sites-available/node_proxy.conf /etc/nginx/sites-enabled/node_proxy.conf | |
/etc/init.d/nginx restart |
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
var http = require('http'); | |
http.createServer(function (req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end('Hello World\n'); | |
}).listen(8124, "127.0.0.1"); | |
console.log('Server running at http://127.0.0.1:8124/'); |
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
# Ubuntu 10.04 Lucid AMI from http://alestic.com/ | |
ec2-run-instances -t c1.medium -n 1 -g default -k default --user-data-file configure_server.sh ami-2d4aa444 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment