Created
July 6, 2011 03:57
-
-
Save dakatsuka/1066534 to your computer and use it in GitHub Desktop.
Node.js + Express + Cluster をデプロイするためのCapistrano Recipe
This file contains hidden or 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
set :shared_children, %w(log pids sock node_modules) | |
set :node_path, "/usr/local/bin" | |
set :node_app, "app.js" | |
namespace :deploy do | |
task :finalize_update, :except => { :no_release => true } do | |
run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true) | |
run "rm -rf #{latest_release}/log #{latest_release}/node_modules #{latest_release}/tmp" | |
run "mkdir -p #{latest_release}/tmp" | |
run <<-CMD | |
ln -s #{shared_path}/pids #{latest_release}/tmp/pids && | |
ln -s #{shared_path}/sock #{latest_release}/tmp/sock && | |
ln -s #{shared_path}/log #{latest_release}/log && | |
ln -s #{shared_path}/node_modules #{latest_release}/node_modules | |
CMD | |
end | |
task :start, :roles => :app do | |
run <<-CMD | |
export PATH=#{node_path}:$PATH && | |
if [ -f #{shared_path}/pids/master.pid ]; \ | |
then echo "Server is already running!"; \ | |
else cd #{current_path} && nohup node app.js >/dev/null 2>&1 & | |
fi | |
CMD | |
end | |
task :restart, :roles => :app do | |
run <<-CMD | |
export PATH=#{node_path}:$PATH && | |
if [ -f #{shared_path}/pids/master.pid ]; \ | |
then cd #{current_path} && node app.js --restart; \ | |
else cd #{current_path} && nohup node app.js >/dev/null 2>&1 & | |
fi | |
CMD | |
end | |
task :stop, :roles => :app do | |
run <<-CMD | |
export PATH=#{node_path}:$PATH && | |
cd #{current_path} && | |
node app.js --shutdown && | |
rm #{shared_path}/pids/*.pid | |
CMD | |
end | |
task :status, :roles => :app do | |
run <<-CMD | |
export PATH=#{node_path}:$PATH && | |
cd #{current_path} && | |
node app.js --status | |
CMD | |
end | |
task :npm_install, :roles => :app do | |
run <<-CMD | |
export PATH=#{node_path}:$PATH && | |
cd #{latest_release} && | |
npm install | |
CMD | |
end | |
end | |
after 'deploy:finalize_update', 'deploy:npm_install' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment