Skip to content

Instantly share code, notes, and snippets.

@jeffbyrnes
Created May 9, 2013 01:31
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jeffbyrnes/5544930 to your computer and use it in GitHub Desktop.
Save jeffbyrnes/5544930 to your computer and use it in GitHub Desktop.
Capistrano recipe for Hubot deployments + Forever
# Lifted from this blog article & modified heavily:
# http://blog.nicolai86.eu/posts/2011-11-03/deploying-hubot-with-capistrano
set :application, "hubot"
set :repository, "repository"
set :scm, :git
set :ssh_options, { :forward_agent => true }
set :branch, "master"
set :deploy_to, "/home/hubot"
set :deploy_via, :remote_cache
set :user, "hubot"
set :use_sudo, false
default_environment['PATH'] = "$HOME/current/node_modules/.bin:$HOME/current/node_modules/hubot/node_modules/.bin:$PATH"
role :web, "your-server"
# if you want to clean up old releases on each deploy uncomment this:
after "deploy:restart", "deploy:cleanup"
namespace :deploy do
desc "Sets up the log file, then sources EnvVars & starts Hubot"
task :start do
log_file = "#{shared_path}/log/hubot.log"
# If we've got a log file already, mark that a deployment occurred
run "if [ -e #{log_file} ]; then echo \"\n\nDeployment #{release_name}\n\" >> #{log_file}; fi"
# Start Hubot!
run "source #{release_path}/.env && \
cd #{release_path} && \
forever start --pidfile #{shared_path}/pids/hubot.pid -a -l #{shared_path}/log/hubot.log -c coffee node_modules/.bin/hubot -a hipchat"
end
desc "Stop Hubot"
task :stop do
run "cd #{release_path} && \
forever stop node_modules/.bin/hubot"
end
desc "Install necessary Node modules, then move them to the correct path"
task :npm_install do
# Install the necessary node packages
run "cd #{release_path} && npm install"
# Move installed Node modules to shared directory
run "mv #{release_path}/node_modules #{shared_path}/node_modules"
end
desc "Create symlink to shared Node modules"
task :npm_modules_make_symlink do
run "ln -s #{shared_path}/node_modules #{release_path}/node_modules"
end
desc "Base task to restart Hubot after a deployment if he's already running"
task :restart do
stop
npm_modules_make_symlink
start
end
desc "A cold start for when Hubot's dead"
task :cold do
update
npm_install
npm_modules_make_symlink
start
end
task :migrate do
# dummy task
end
task :migrations do
# dummy task
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment