2011-06-30 20:06:23 +08:00
|
|
|
# node deploy config
|
|
|
|
|
2011-07-01 00:10:10 +08:00
|
|
|
# first time deploy:
|
|
|
|
# cap production deploy:setup
|
|
|
|
# cap production deploy
|
|
|
|
# cap production node:npm_dependencies
|
|
|
|
# cap production restart #<-- not made yet
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-06-30 20:06:23 +08:00
|
|
|
# somehow we'll have to update this dynamically
|
|
|
|
set :host_1, "174.129.61.69"
|
2011-06-30 22:55:04 +08:00
|
|
|
role :app, host_1
|
|
|
|
|
|
|
|
ssh_options[:forward_agent] = true
|
2011-06-30 20:06:23 +08:00
|
|
|
|
|
|
|
# repository
|
|
|
|
set :application, "node-sql-api"
|
|
|
|
set :repository, "git@github.com:tokumine/cartodb-sql-api.git"
|
|
|
|
set :scm, :git
|
2011-06-30 22:55:04 +08:00
|
|
|
set :deploy_via, :remote_cache
|
2011-06-30 20:06:23 +08:00
|
|
|
|
|
|
|
# deploy settings
|
|
|
|
set :node_file, "cluster.js"
|
|
|
|
set :deploy_to, "/home/ubuntu/www/#{application}"
|
|
|
|
set :user, "ubuntu"
|
|
|
|
set :runner, "ubuntu"
|
2011-06-30 22:55:04 +08:00
|
|
|
set :use_sudo, false
|
2011-06-30 20:06:23 +08:00
|
|
|
|
|
|
|
default_run_options[:pty] = true
|
|
|
|
|
2011-07-01 00:10:10 +08:00
|
|
|
after "deploy", "node:link_directories"
|
2011-06-30 22:55:04 +08:00
|
|
|
|
|
|
|
# ensures ssh-agent is always running
|
2011-07-01 18:51:16 +08:00
|
|
|
before 'deploy:setup', 'deploy:create_deploy_to_with_sudo'
|
2011-06-30 22:55:04 +08:00
|
|
|
after "deploy:setup", "deploy:setup_deploy_keys"
|
2011-07-01 00:10:10 +08:00
|
|
|
after "deploy:setup", "deploy:setup_node_directories"
|
2011-07-01 18:51:16 +08:00
|
|
|
after 'deploy:setup', 'deploy:write_upstart_script'
|
2011-07-01 00:10:10 +08:00
|
|
|
|
2011-06-30 22:55:04 +08:00
|
|
|
namespace :deploy do
|
2011-07-01 00:10:10 +08:00
|
|
|
desc "setup ssh-agent"
|
2011-06-30 22:55:04 +08:00
|
|
|
task :setup_deploy_keys do
|
|
|
|
run "echo 'eval `ssh-agent`' >> ~/.bashrc"
|
2011-07-01 00:10:10 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
desc "configure shared directory"
|
|
|
|
task :setup_node_directories do
|
|
|
|
run "mkdir -p #{shared_path}/logs"
|
|
|
|
run "mkdir -p #{shared_path}/pids"
|
|
|
|
end
|
2011-07-01 18:51:16 +08:00
|
|
|
|
|
|
|
task :start, :roles => :app, :except => { :no_release => true } do
|
|
|
|
sudo "start #{application}"
|
|
|
|
end
|
|
|
|
|
|
|
|
task :stop, :roles => :app, :except => { :no_release => true } do
|
|
|
|
sudo "stop #{application}"
|
|
|
|
end
|
|
|
|
|
2011-07-01 00:10:10 +08:00
|
|
|
task :restart, :roles => :app, :except => { :no_release => true } do
|
2011-07-01 18:51:16 +08:00
|
|
|
sudo "restart #{application} || sudo start #{application}"
|
|
|
|
end
|
|
|
|
|
|
|
|
task :create_deploy_to_with_sudo, :roles => :app do
|
|
|
|
sudo "mkdir -p #{deploy_to}"
|
|
|
|
sudo "chown #{user}:#{user} #{deploy_to}"
|
2011-06-30 22:55:04 +08:00
|
|
|
end
|
2011-07-01 18:51:16 +08:00
|
|
|
|
|
|
|
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/#{user}"
|
|
|
|
|
|
|
|
cd #{current_path}
|
|
|
|
exec sudo -u #{user} sh -c "/home/ubuntu/local/node/bin/node #{current_path}/#{node_file} production >> #{shared_path}/logs/#{application}.log 2>&1"
|
|
|
|
end script
|
|
|
|
respawn
|
|
|
|
UPSTART
|
|
|
|
|
|
|
|
put upstart_script, "/tmp/#{application}_upstart.conf"
|
|
|
|
sudo "mv /tmp/#{application}_upstart.conf /etc/init/#{application}.conf"
|
|
|
|
end
|
2011-06-30 22:55:04 +08:00
|
|
|
end
|
2011-07-01 00:10:10 +08:00
|
|
|
|
2011-07-01 18:51:16 +08:00
|
|
|
|
2011-07-01 00:10:10 +08:00
|
|
|
namespace :node do
|
|
|
|
desc "recreates symbolic links to shared directories"
|
|
|
|
task :link_directories do
|
|
|
|
run "rm #{current_path}/log"
|
|
|
|
run "ln -s #{shared_path}/logs #{current_path}/logs"
|
|
|
|
run "ln -s #{shared_path}/pids #{current_path}/pids"
|
|
|
|
run "ln -s #{shared_path}/node_modules #{current_path}/node_modules"
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "install dependencies"
|
|
|
|
task :npm_dependencies, :roles => :app do
|
|
|
|
run "cd #{current_path} && npm install"
|
|
|
|
run "mv -f #{current_path}/node_modules #{shared_path}/node_modules"
|
|
|
|
run "ln -s #{shared_path}/node_modules #{current_path}/node_modules"
|
|
|
|
end
|
|
|
|
end
|