diff --git a/Changes.md b/Changes.md index 36e21656..40f9daa7 100644 --- a/Changes.md +++ b/Changes.md @@ -1,6 +1,8 @@ HEAD ----------- +- Add capistrano support, just require 'sidekiq/capistrano' in config/deploy.rb. +- Workers now log upon start and finish (mperham) - Messages for terminated workers are now automatically requeued (mperham) - Add support for Exceptional error reporting (bensie) diff --git a/lib/sidekiq/capistrano.rb b/lib/sidekiq/capistrano.rb new file mode 100644 index 00000000..96345fc9 --- /dev/null +++ b/lib/sidekiq/capistrano.rb @@ -0,0 +1,29 @@ +Capistrano::Configuration.instance.load do + after "deploy", "sidekiq:restart" + + namespace :sidekiq do + + desc "Force stop sidekiq" + task :kill do + run "cd #{current_path} && kill `cat tmp/pids/sidekiq.pid` && sleep 5 && kill -9 `cat tmp/pids/sidekiq.pid`" + end + + desc "Stop sidekiq" + task :stop do + run "cd #{current_path} && kill `cat tmp/pids/sidekiq.pid`" + end + + desc "Start sidekiq" + task :start do + rails_env = fetch(:rails_env, "production") + run "cd #{current_path} && bundle exec sidekiq -e #{rails_env} -C config/sidekiq.yml -P tmp/pids/sidekiq.pid >> log/sidekiq.log &" + end + + desc "Restart sidekiq" + task :restart do + stop + start + end + + end +end diff --git a/myapp/Capfile b/myapp/Capfile new file mode 100644 index 00000000..98743d10 --- /dev/null +++ b/myapp/Capfile @@ -0,0 +1,5 @@ +load 'deploy' +# Uncomment if you are using Rails' asset pipeline + # load 'deploy/assets' +Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) } +load 'config/deploy' # remove this line to skip loading any of the default tasks \ No newline at end of file diff --git a/myapp/Gemfile b/myapp/Gemfile index 569e5198..204f1c6e 100644 --- a/myapp/Gemfile +++ b/myapp/Gemfile @@ -4,3 +4,4 @@ gem 'rails', '3.2.1' gem 'sqlite3' gem 'sidekiq', :path => '..' gem 'resque' +gem 'capistrano' diff --git a/myapp/Gemfile.lock b/myapp/Gemfile.lock index f68b03ec..e57245ad 100644 --- a/myapp/Gemfile.lock +++ b/myapp/Gemfile.lock @@ -40,9 +40,16 @@ GEM multi_json (~> 1.0) arel (3.0.2) builder (3.0.0) + capistrano (2.11.2) + highline + net-scp (>= 1.0.0) + net-sftp (>= 2.0.0) + net-ssh (>= 2.0.14) + net-ssh-gateway (>= 1.1.0) celluloid (0.9.0) connection_pool (0.1.0) erubis (2.7.0) + highline (1.6.11) hike (1.2.1) i18n (0.6.0) journey (1.0.2) @@ -53,6 +60,13 @@ GEM treetop (~> 1.4.8) mime-types (1.17.2) multi_json (1.1.0) + net-scp (1.0.4) + net-ssh (>= 1.99.1) + net-sftp (2.0.5) + net-ssh (>= 2.0.9) + net-ssh (2.3.0) + net-ssh-gateway (1.1.0) + net-ssh (>= 1.99.1) polyglot (0.3.3) rack (1.4.1) rack-cache (1.1) @@ -111,6 +125,7 @@ PLATFORMS ruby DEPENDENCIES + capistrano rails (= 3.2.1) resque sidekiq! diff --git a/myapp/config/deploy.rb b/myapp/config/deploy.rb new file mode 100644 index 00000000..723df61b --- /dev/null +++ b/myapp/config/deploy.rb @@ -0,0 +1,15 @@ +require 'bundler/capistrano' +require 'sidekiq/capistrano' + +set :scm, :git +set :repository, 'git@github.com:mperham/sidekiq' +ssh_options[:forward_agent] = true + +default_run_options[:pty] = true # needed to run sudo +set :user, 'mperham' +set :application, "myapp" +set :deploy_via, :remote_cache + +role :web, "localhost" +role :app, "localhost" +role :db, "localhost", :primary => true