├── lib ├── capistrano-shoryuken.rb └── capistrano │ ├── shoryuken │ └── version.rb │ ├── shoryuken.rb │ └── tasks │ ├── capistrano2.rb │ └── shoryuken.cap ├── Rakefile ├── .gitignore ├── capistrano-shoryuken.gemspec ├── README.md └── LICENSE /lib/capistrano-shoryuken.rb: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/gem_tasks' -------------------------------------------------------------------------------- /lib/capistrano/shoryuken/version.rb: -------------------------------------------------------------------------------- 1 | module Capistrano 2 | module Shoryuken 3 | VERSION = '0.1.5' 4 | end 5 | end -------------------------------------------------------------------------------- /lib/capistrano/shoryuken.rb: -------------------------------------------------------------------------------- 1 | if Gem::Specification.find_by_name('capistrano').version >= Gem::Version.new('3.0.0') 2 | load File.expand_path('../tasks/shoryuken.cap', __FILE__) 3 | else 4 | require_relative 'tasks/capistrano2' 5 | end 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .buildpath 2 | .project 3 | .settings 4 | *.gem 5 | *.rbc 6 | /.config 7 | /coverage/ 8 | /InstalledFiles 9 | /pkg/ 10 | /spec/reports/ 11 | /test/tmp/ 12 | /test/version_tmp/ 13 | /tmp/ 14 | 15 | ## Specific to RubyMotion: 16 | .dat* 17 | .repl_history 18 | build/ 19 | 20 | ## Documentation cache and generated files: 21 | /.yardoc/ 22 | /_yardoc/ 23 | /doc/ 24 | /rdoc/ 25 | 26 | ## Environment normalisation: 27 | /.bundle/ 28 | /lib/bundler/man/ 29 | 30 | # for a library or gem, you might want to ignore these files since the code is 31 | # intended to run in multiple environments; otherwise, check them in: 32 | # Gemfile.lock 33 | # .ruby-version 34 | # .ruby-gemset 35 | 36 | # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: 37 | .rvmrc 38 | -------------------------------------------------------------------------------- /capistrano-shoryuken.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require "capistrano/shoryuken/version" 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "capistrano-shoryuken" 8 | spec.version = Capistrano::Shoryuken::VERSION 9 | spec.authors = ["Joe Khoobyar"] 10 | spec.email = ["joe@khoobyar.name"] 11 | spec.homepage = "http://github.com/joekhoobyar/capistrano-shoryuken" 12 | spec.summary = 'Shoryuken integration for Capistrano' 13 | spec.description = 'Shoryuken integration for Capistrano' 14 | 15 | spec.license = "LGPL-3.0" 16 | spec.files = `git ls-files -z`.split("\x0") 17 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) 18 | spec.require_paths = ["lib"] 19 | 20 | spec.required_ruby_version = '>= 1.9.2' 21 | 22 | spec.add_dependency 'capistrano' 23 | end 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # capistrano-shoryuken 2 | Shoryuken integration for Capistrano. Loosely based on `capistrano-sidekiq` 3 | 4 | ## Installation 5 | 6 | Add this line to your application's Gemfile: 7 | 8 | gem 'capistrano-shoryuken', github: 'joekhoobyar/capistrano-shoryuken' 9 | 10 | or: 11 | 12 | gem 'capistrano-shoryuken', group: :development 13 | 14 | And then execute: 15 | 16 | $ bundle 17 | 18 | 19 | ## Usage 20 | ```ruby 21 | # Capfile 22 | 23 | require 'capistrano/shoryuken' 24 | ``` 25 | 26 | 27 | Configurable options, shown here with defaults (using Capistrano 3 syntax): 28 | 29 | ```ruby 30 | # config/deploy.rb 31 | 32 | # Whether or not to hook into the default deployment recipe. 33 | set :shoryuken_default_hooks, true 34 | 35 | set :shoryuken_pid, -> { File.join(shared_path, 'tmp', 'pids', 'shoryuken.pid') } 36 | set :shoryuken_env, -> { fetch(:rack_env, fetch(:rails_env, fetch(:stage))) } 37 | set :shoryuken_log, -> { File.join(shared_path, 'log', 'shoryuken.log') } 38 | set :shoryuken_config, -> { File.join(release_path, 'config', 'shoryuken.yml') } 39 | set :shoryuken_requires, -> { [] } 40 | set :shoryuken_options, -> { ['--rails'] } 41 | set :shoryuken_queues, -> { [] } 42 | set :shoryuken_role, :app 43 | ``` 44 | 45 | ## Changelog 46 | - 0.1.5: Bug fix when using Capistrano 2 47 | - 0.1.4: Minimum ruby 1.9.2 48 | - 0.1.3: Fix erroneous auto-loading from Bundler.require 49 | - 0.1.2: Support --require option. 50 | - 0.1.1: Default --rails option. Support Capistrano 3 51 | - 0.1.0: Support Capistrano 2 52 | 53 | ## Contributors 54 | 55 | - [Joe Khoobyar] (https://github.com/joekhoobyar) 56 | 57 | ## Contributing 58 | 59 | 1. Fork it 60 | 2. Create your feature branch (`git checkout -b my-new-feature`) 61 | 3. Commit your changes (`git commit -am 'Add some feature'`) 62 | 4. Push to the branch (`git push origin my-new-feature`) 63 | 5. Create new Pull Request 64 | -------------------------------------------------------------------------------- /lib/capistrano/tasks/capistrano2.rb: -------------------------------------------------------------------------------- 1 | Capistrano::Configuration.instance.load do 2 | 3 | _cset(:shoryuken_default_hooks) { true } 4 | 5 | _cset(:shoryuken_pid) { File.join(shared_path, 'pids', 'shoryuken.pid') } 6 | _cset(:shoryuken_env) { fetch(:rack_env, fetch(:rails_env, 'production')) } 7 | _cset(:shoryuken_log) { File.join(shared_path, 'log', 'shoryuken.log') } 8 | _cset(:shoryuken_config) { "#{current_path}/config/shoryuken.yml" } 9 | _cset(:shoryuken_requires) { [] } 10 | _cset(:shoryuken_queues) { [] } 11 | _cset(:shoryuken_options) { '--rails' } 12 | 13 | _cset(:shoryuken_cmd) { "#{fetch(:bundle_cmd, 'bundle')} exec shoryuken" } 14 | 15 | _cset(:shoryuken_role) { :app } 16 | 17 | if fetch(:shoryuken_default_hooks) 18 | after 'deploy:stop', 'shoryuken:stop' 19 | after 'deploy:start', 'shoryuken:start' 20 | before 'deploy:restart', 'shoryuken:restart' 21 | end 22 | 23 | namespace :shoryuken do 24 | desc 'Stop the shoryuken process, gracefully' 25 | task :stop, roles: lambda { fetch(:shoryuken_role) }, on_no_matching_servers: :continue do 26 | pid_file = fetch(:shoryuken_pid) 27 | 28 | run "cd #{current_path} ; kill -USR1 `cat '#{pid_file}'` >/dev/null 2>&1 || true" 29 | print 'Waiting for shoryuken to shutdown...' 30 | run "cd #{current_path} && while [ -f '#{pid_file}' ] && kill -0 `cat '#{pid_file}'` >/dev/null 2>&1; do sleep 1; done && rm -f '#{pid_file}'" 31 | end 32 | 33 | desc 'Shutdown the shoryuken process, immediately' 34 | task :shutdown, roles: lambda { fetch(:shoryuken_role) }, on_no_matching_servers: :continue do 35 | run "cd #{current_path} && [ -f '#{pid_file}' ] && kill `cat '#{pid_file}'`" 36 | end 37 | 38 | desc 'Start the shoryuken process' 39 | task :start, roles: lambda { fetch(:shoryuken_role) }, on_no_matching_servers: :continue do 40 | pid_file = fetch(:shoryuken_pid) 41 | 42 | args = ['--daemon'] 43 | args.push "--pidfile '#{pid_file}'" 44 | logfile = fetch(:shoryuken_log) and args.push "--logfile '#{logfile}'" 45 | config = fetch(:shoryuken_config) and args.push "--config '#{config}'" 46 | queues = Array(fetch(:shoryuken_queues)) and queues.each{|queue| args.push "--queue #{queue}" } 47 | reqs = Array(fetch(:shoryuken_requires)) and reqs.each{|req| args.push "--require #{req}" } 48 | options = fetch(:shoryuken_options) and args.push Array(options).join(' ') 49 | 50 | cmd = fetch(:shoryuken_cmd) 51 | env = fetch(:shoryuken_env) and cmd = "RAILS_ENV=#{env} #{cmd}" 52 | 53 | run "cd #{current_path} && if [ -f '#{pid_file}' ] && kill -0 `cat '#{pid_file}'` >/dev/null 2>&1 ; then echo 'shoryuken is already running'; else #{cmd} #{args.compact.join(' ')} ; fi" 54 | end 55 | 56 | desc 'Restart shoryuken' 57 | task :restart, roles: lambda { fetch(:shoryuken_role) }, on_no_matching_servers: :continue do 58 | stop 59 | start 60 | end 61 | 62 | desc 'Make the shoryuken process log detailed status information' 63 | task :log_status, roles: lambda { fetch(:shoryuken_role) }, on_no_matching_servers: :continue do 64 | pid_file = fetch(:shoryuken_pid) 65 | 66 | run "cd #{current_path} && [ -f '#{pid_file}' ] && kill -TTIN `cat '#{pid_file}'`" 67 | end 68 | 69 | desc 'Tail the shoryuken log forever' 70 | task :tail_log, roles: lambda { fetch(:shoryuken_role) }, on_no_matching_servers: :continue do 71 | run "tail -f '#{fetch(:shoryuken_log)}'" 72 | end 73 | 74 | desc 'Tail ENV[number] lines of the shoryuken log' 75 | task :tail_log_lines, roles: lambda { fetch(:shoryuken_role) }, on_no_matching_servers: :continue do 76 | run "tail -n #{ENV.fetch('number',20)} '#{fetch(:shoryuken_log)}'" 77 | end 78 | end 79 | end 80 | -------------------------------------------------------------------------------- /lib/capistrano/tasks/shoryuken.cap: -------------------------------------------------------------------------------- 1 | namespace :load do 2 | task :defaults do 3 | set :shoryuken_default_hooks, -> { true } 4 | 5 | set :shoryuken_pid, -> { File.join(shared_path, 'tmp', 'pids', 'shoryuken.pid') } 6 | set :shoryuken_env, -> { fetch(:rack_env, fetch(:rails_env, fetch(:stage))) } 7 | set :shoryuken_log, -> { File.join(shared_path, 'log', 'shoryuken.log') } 8 | set :shoryuken_config, -> { File.join(release_path, 'config', 'shoryuken.yml') } 9 | set :shoryuken_requires, -> { [] } 10 | set :shoryuken_queues, -> { [] } 11 | set :shoryuken_options, -> { '--rails' } 12 | 13 | set :shoryuken_role, -> { :app } 14 | 15 | # Rbenv and RVM integration 16 | set :rbenv_map_bins, fetch(:rbenv_map_bins).to_a.concat(%w(shoryuken)) 17 | set :rvm_map_bins, fetch(:rvm_map_bins).to_a.concat(%w(shoryuken)) 18 | end 19 | end 20 | 21 | namespace :deploy do 22 | before :starting, :check_shoryuken_hooks do 23 | invoke 'shoryuken:add_default_hooks' if fetch(:shoryuken_default_hooks) 24 | end 25 | after :publishing, :restart_shoryuken do 26 | invoke 'shoryuken:restart' if fetch(:shoryuken_default_hooks) 27 | end 28 | end 29 | 30 | namespace :shoryuken do 31 | 32 | def pid_file_signal(pid_file, signal=nil, options={}) 33 | args = ['kill', "-#{signal}", '$(', 'cat', pid_file, ')'] 34 | args.delete_at(1) if args[1]=='-' 35 | if options[:quiet] 36 | args << '>/dev/null' << '2>&1' 37 | test(*args) 38 | else 39 | execute(*args) 40 | end 41 | end 42 | 43 | def pid_file_exists?(pid_file) 44 | test('[', '-f', pid_file, ']') 45 | end 46 | 47 | def pid_process_exists?(pid_file) 48 | pid_file_exists?(pid_file) and pid_file_signal(pid_file, '0', quiet: true) 49 | end 50 | 51 | task :add_default_hooks do 52 | after 'deploy:updated', 'shoryuken:stop' 53 | after 'deploy:reverted', 'shoryuken:stop' 54 | after 'deploy:published', 'shoryuken:start' 55 | end 56 | 57 | desc 'Stop the shoryuken process, gracefully' 58 | task :stop do 59 | on roles fetch(:shoryuken_role) do 60 | within release_path do 61 | pid_file = fetch(:shoryuken_pid) 62 | if pid_file_exists?(pid_file) 63 | pid_file_signal pid_file, 'USR1', quiet: true 64 | 65 | print 'Waiting for shoryuken to shutdown...' 66 | sleep 1 while pid_process_exists?(pid_file) 67 | execute :rm, '-f', pid_file 68 | end 69 | end 70 | end 71 | end 72 | 73 | desc 'Shutdown the shoryuken process, immediately' 74 | task :shutdown do 75 | on roles fetch(:shoryuken_role) do 76 | within release_path do 77 | pid_file = fetch(:shoryuken_pid) 78 | pid_file_signal pid_file if pid_file_exists?(pid_file) 79 | end 80 | end 81 | end 82 | 83 | desc 'Start the shoryuken process' 84 | task :start do 85 | on roles fetch(:shoryuken_role) do 86 | within release_path do 87 | pid_file = fetch(:shoryuken_pid) 88 | unless pid_process_exists?(pid_file) 89 | args = ['--daemon'] 90 | args.push "--pidfile '#{pid_file}'" 91 | logfile = fetch(:shoryuken_log) and args.push "--logfile '#{logfile}'" 92 | config = fetch(:shoryuken_config) and args.push "--config '#{config}'" 93 | queues = Array(fetch(:shoryuken_queues)) and queues.each{|queue| args.push "--queue #{queue}" } 94 | reqs = Array(fetch(:shoryuken_requires)) and reqs.each{|req| args.push "--require #{req}" } 95 | options = fetch(:shoryuken_options) and args.push Array(options).join(' ') 96 | 97 | with rails_env: fetch(:shoryuken_env) do 98 | execute :bundle, :exec, :shoryuken, args.compact.join(' ') 99 | end 100 | end 101 | end 102 | end 103 | end 104 | 105 | desc 'Restart shoryuken' 106 | task :restart do 107 | invoke 'shoryuken:stop' 108 | invoke 'shoryuken:start' 109 | end 110 | 111 | desc 'Make the shoryuken process log detailed status information' 112 | task :log_status do 113 | on roles fetch(:shoryuken_role) do 114 | pid_file = fetch(:shoryuken_pid) 115 | pid_file_signal pid_file, 'TTIN' if pid_file_exists?(pid_file) 116 | end 117 | end 118 | 119 | desc 'Tail the shoryuken log forever' 120 | task :tail_log do 121 | on roles fetch(:shoryuken_role) do 122 | log_file = fetch(:shoryuken_log) 123 | execute :tail, '-f', log_file if test('[', '-f', log_file, ']') 124 | end 125 | end 126 | 127 | desc 'Tail ENV[number] lines of the shoryuken log' 128 | task :tail_log_lines do 129 | on roles fetch(:shoryuken_role) do 130 | log_file = fetch(:shoryuken_log) 131 | execute :tail, '-n', ENV.fetch('number',20).to_s, log_file if test('[', '-f', log_file, ']') 132 | end 133 | end 134 | end 135 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | 167 | --------------------------------------------------------------------------------