capistrano-rainbows 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 15f96b073a2639f6c611f1f30d27caf731a9fbb5
4
+ data.tar.gz: 0e97d69816bbc08d08df1098bba3cef9f2cf68e2
5
+ SHA512:
6
+ metadata.gz: b174dd2ea24620c640cce9213883fb57cf967642b5c963e99fbf4d3766891a9d8c4e90f23b976b8d64e7072f6bf9a556f540fab3a4600e7d8ddf7d9b0ac9753b
7
+ data.tar.gz: 8875bc3ab395a9d0ab14422ed4a5d1857345423d6860638e5cdb858cf9a7c87e1eae5efc73f6e6219f738b4bd9f2b5057f4126a8ac8439aa56fdbfd8e2ef9715
data/.gitignore ADDED
@@ -0,0 +1,41 @@
1
+ !.gitignore
2
+ *.gem
3
+ *.rbc
4
+ *.sw[a-p]
5
+ *.tmproj
6
+ *.tmproject
7
+ *.un~
8
+ *~
9
+ .DS_Store
10
+ .Spotlight-V100
11
+ .Trashes
12
+ ._*
13
+ .bundle
14
+ .config
15
+ .directory
16
+ .elc
17
+ .redcar
18
+ .yardoc
19
+ /.emacs.desktop
20
+ /.emacs.desktop.lock
21
+ Desktop.ini
22
+ Gemfile.lock
23
+ Icon?
24
+ InstalledFiles
25
+ Session.vim
26
+ Thumbs.db
27
+ \#*\#
28
+ _yardoc
29
+ auto-save-list
30
+ coverage
31
+ doc/
32
+ lib/bundler/man
33
+ pkg
34
+ pkg/*
35
+ rdoc
36
+ spec/reports
37
+ test/tmp
38
+ test/version_tmp
39
+ tmp
40
+ tmtags
41
+ tramp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012-2013 H2ocube.com
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9
+ of the Software, and to permit persons to whom the Software is furnished to
10
+ do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16
+ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
17
+ PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # Capistrano Rainbows
2
+
3
+ Capistrano plugin that integrates Rainbows tasks into capistrano deployment script.
4
+
5
+ ## Installation
6
+
7
+ Install library from rubygems:
8
+
9
+ ```
10
+ gem install capistrano-rainbows
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### Setup
16
+
17
+ Add the library to your `Gemfile`:
18
+
19
+ ```ruby
20
+ group :development do
21
+ gem 'capistrano-rainbows', require: false
22
+ end
23
+ ```
24
+
25
+ And load it into your deployment script `config/deploy.rb`:
26
+
27
+ ```ruby
28
+ require 'capistrano-rainbows'
29
+ ```
30
+
31
+ Add rainbows restart task hook:
32
+
33
+ ```ruby
34
+ after 'deploy:restart', 'rainbows:reload' # app IS NOT preloaded
35
+ after 'deploy:restart', 'rainbows:restart' # app preloaded
36
+ ```
37
+
38
+ Create a new configuration file `config/rainbows/rainbows.rb` or `config/rainbows/STAGE.rb`, where stage is your deployment environment.
39
+
40
+ Example config - [examples/rails3.rb](https://github.com/sosedoff/capistrano-rainbows/blob/master/examples/rails3.rb). Please refer to rainbows documentation for more examples and configuration options.
41
+
42
+ ### Test
43
+
44
+ First, make sure you're running the latest release:
45
+
46
+ ```
47
+ cap deploy
48
+ ```
49
+
50
+ Then you can test each individual task:
51
+
52
+ ```
53
+ cap rainbows:start
54
+ cap rainbows:stop
55
+ cap rainbows:reload
56
+ ```
57
+
58
+ ## Configuration
59
+
60
+ You can modify any of the following options in your `deploy.rb` config.
61
+
62
+ - `rainbows_env` - Set rainbows environment. Default to `rails_env` variable.
63
+ - `rainbows_pid` - Set rainbows PID file path. Default to `current_path/tmp/pids/rainbows.pid`
64
+ - `rainbows_bin` - Set rainbows executable file. Default to `rainbows`.
65
+ - `rainbows_bundle` - Set bundler command for rainbows. Default to `bundle`.
66
+ - `rainbows_user` - Launch rainbows master as the specified user. Default to `user` variable.
67
+ - `rainbows_roles` - Define which roles to perform rainbows recpies on. Default to `:app`.
68
+ - `rainbows_config_path` - Set the directory where rainbows config files reside. Default to `current_path/config`.
69
+ - `rainbows_config_filename` - Set the filename of the rainbows config file. Not used in multistage installations. Default to `rainbows.rb`.
70
+
71
+ ## Available Tasks
72
+
73
+ To get a list of all capistrano tasks, run `cap -T`:
74
+
75
+ ```
76
+ cap rainbows:add_worker # Add a new worker
77
+ cap rainbows:remove_worker # Remove amount of workers
78
+ cap rainbows:reload # Reload rainbows
79
+ cap rainbows:restart # Restart rainbows
80
+ cap rainbows:shutdown # Immediately shutdown rainbows
81
+ cap rainbows:start # Start rainbows master process
82
+ cap rainbows:stop # Stop rainbows
83
+ ```
84
+
85
+ ## License
86
+
87
+ See LICENSE file for details.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ require 'bundler/gem_tasks'
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = 'capistrano-rainbows'
5
+ gem.version = '0.0.1'
6
+ gem.author = 'Ben'
7
+ gem.email = 'ben@h2ocube.com'
8
+ gem.homepage = 'https://github.com/h2ocube/capistrano-rainbows'
9
+ gem.summary = %q{Rainbows integration for Capistrano}
10
+ gem.description = %q{Capistrano plugin that integrates Rainbows server tasks.}
11
+
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
15
+ gem.require_paths = ['lib']
16
+
17
+ gem.add_development_dependency 'rake'
18
+
19
+ gem.add_runtime_dependency 'capistrano'
20
+ end
@@ -0,0 +1,45 @@
1
+ # ------------------------------------------------------------------------------
2
+ # Sample rails 3 config
3
+ # ------------------------------------------------------------------------------
4
+
5
+ # Set your full path to application.
6
+ app_path = "/path/to/app"
7
+
8
+ # Set rainbows options
9
+ worker_processes 1
10
+ preload_app true
11
+ timeout 180
12
+ listen "127.0.0.1:9000"
13
+
14
+ # Spawn rainbows master worker for user apps (group: apps)
15
+ user 'apps', 'apps'
16
+
17
+ # Fill path to your app
18
+ working_directory app_path
19
+
20
+ # Should be 'production' by default, otherwise use other env
21
+ rails_env = ENV['RAILS_ENV'] || 'production'
22
+
23
+ # Log everything to one file
24
+ stderr_path "log/rainbows.log"
25
+ stdout_path "log/rainbows.log"
26
+
27
+ # Set master PID location
28
+ pid "#{app_path}/tmp/pids/rainbows.pid"
29
+
30
+ before_fork do |server, worker|
31
+ ActiveRecord::Base.connection.disconnect!
32
+
33
+ old_pid = "#{server.config[:pid]}.oldbin"
34
+ if File.exists?(old_pid) && server.pid != old_pid
35
+ begin
36
+ Process.kill("QUIT", File.read(old_pid).to_i)
37
+ rescue Errno::ENOENT, Errno::ESRCH
38
+ # someone else did our job for us
39
+ end
40
+ end
41
+ end
42
+
43
+ after_fork do |server, worker|
44
+ ActiveRecord::Base.establish_connection
45
+ end
@@ -0,0 +1 @@
1
+ require 'capistrano-rainbows/capistrano_integration'
@@ -0,0 +1,225 @@
1
+ require 'capistrano'
2
+
3
+ module CapistranoRainbows
4
+ class CapistranoIntegration
5
+ TASKS = [
6
+ 'rainbows:start',
7
+ 'rainbows:stop',
8
+ 'rainbows:restart',
9
+ 'rainbows:duplicate',
10
+ 'rainbows:reload',
11
+ 'rainbows:shutdown',
12
+ 'rainbows:add_worker',
13
+ 'rainbows:remove_worker'
14
+ ]
15
+
16
+ def self.load_into(capistrano_config)
17
+ capistrano_config.load do
18
+ before(CapistranoIntegration::TASKS) do
19
+ _cset(:app_env) { (fetch(:rails_env) rescue 'production') }
20
+ _cset(:rainbows_pid) { "#{fetch(:current_path)}/tmp/pids/rainbows.pid" }
21
+ _cset(:rainbows_env) { fetch(:app_env) }
22
+ _cset(:rainbows_bin) { "rainbows" }
23
+ _cset(:rainbows_bundle) { fetch(:bundle_cmd) rescue 'bundle' }
24
+ _cset(:rainbows_restart_sleep_time) { 2 }
25
+ _cset(:rainbows_user) { nil }
26
+ _cset(:rainbows_config_path) { "#{fetch(:current_path)}/config" }
27
+ _cset(:rainbows_config_filename) { "rainbows.rb" }
28
+ end
29
+
30
+ # Check if a remote process exists using its pid file
31
+ #
32
+ def remote_process_exists?(pid_file)
33
+ "[ -e #{pid_file} ] && #{try_rainbows_user} kill -0 `cat #{pid_file}` > /dev/null 2>&1"
34
+ end
35
+
36
+ # Stale rainbows process pid file
37
+ #
38
+ def old_rainbows_pid
39
+ "#{rainbows_pid}.oldbin"
40
+ end
41
+
42
+ # Command to check if rainbows is running
43
+ #
44
+ def rainbows_is_running?
45
+ remote_process_exists?(rainbows_pid)
46
+ end
47
+
48
+ # Command to check if stale rainbows is running
49
+ #
50
+ def old_rainbows_is_running?
51
+ remote_process_exists?(old_rainbows_pid)
52
+ end
53
+
54
+ # Get rainbows master process PID (using the shell)
55
+ #
56
+ def get_rainbows_pid(pid_file=rainbows_pid)
57
+ "`cat #{pid_file}`"
58
+ end
59
+
60
+ # Get rainbows master (old) process PID
61
+ #
62
+ def get_old_rainbows_pid
63
+ get_rainbows_pid(old_rainbows_pid)
64
+ end
65
+
66
+ # Send a signal to a rainbows master processes
67
+ #
68
+ def rainbows_send_signal(signal, pid=get_rainbows_pid)
69
+ "#{try_rainbows_user} kill -s #{signal} #{pid}"
70
+ end
71
+
72
+ # Run a command as the :rainbows_user user if :rainbows_user is a string.
73
+ # Otherwise run as default (:user) user.
74
+ #
75
+ def try_rainbows_user
76
+ "#{sudo :as => rainbows_user.to_s}" if rainbows_user.kind_of?(String)
77
+ end
78
+
79
+ # Kill rainbowss in multiple ways O_O
80
+ #
81
+ def kill_rainbows(signal)
82
+ script = <<-END
83
+ if #{rainbows_is_running?}; then
84
+ echo "Stopping rainbows...";
85
+ #{rainbows_send_signal(signal)};
86
+ else
87
+ echo "rainbows is not running.";
88
+ fi;
89
+ END
90
+
91
+ script
92
+ end
93
+
94
+ # Start the rainbows server
95
+ #
96
+ def start_rainbows
97
+ primary_config_path = "#{rainbows_config_path}/#{rainbows_config_filename}"
98
+ secondary_config_path = "#{rainbows_config_path}/rainbows/#{rainbows_env}.rb"
99
+
100
+ script = <<-END
101
+ if [ -e #{primary_config_path} ]; then
102
+ rainbows_CONFIG_PATH=#{primary_config_path};
103
+ else
104
+ if [ -e #{secondary_config_path} ]; then
105
+ rainbows_CONFIG_PATH=#{secondary_config_path};
106
+ else
107
+ echo "Config file for \"#{rainbows_env}\" environment was not found at either \"#{primary_config_path}\" or \"#{secondary_config_path}\"";
108
+ exit 1;
109
+ fi;
110
+ fi;
111
+
112
+ if [ -e #{rainbows_pid} ]; then
113
+ if #{try_rainbows_user} kill -0 `cat #{rainbows_pid}` > /dev/null 2>&1; then
114
+ echo "rainbows is already running!";
115
+ exit 0;
116
+ fi;
117
+
118
+ #{try_rainbows_user} rm #{rainbows_pid};
119
+ fi;
120
+
121
+ echo "Starting rainbows...";
122
+ cd #{current_path} && #{try_rainbows_user} BUNDLE_GEMFILE=#{current_path}/Gemfile #{rainbows_bundle} exec #{rainbows_bin} -c $rainbows_CONFIG_PATH -E #{app_env} -D;
123
+ END
124
+
125
+ script
126
+ end
127
+
128
+ def duplicate_rainbows
129
+ script = <<-END
130
+ if #{rainbows_is_running?}; then
131
+ echo "Duplicating rainbows...";
132
+ #{rainbows_send_signal('USR2')};
133
+ else
134
+ #{start_rainbows}
135
+ fi;
136
+ END
137
+
138
+ script
139
+ end
140
+
141
+ def rainbows_roles
142
+ fetch(:rainbows_roles, :app)
143
+ end
144
+
145
+ #
146
+ # rainbows cap tasks
147
+ #
148
+ namespace :rainbows do
149
+ desc 'Start rainbows master process'
150
+ task :start, :roles => rainbows_roles, :except => {:no_release => true} do
151
+ run start_rainbows
152
+ end
153
+
154
+ desc 'Stop rainbows'
155
+ task :stop, :roles => rainbows_roles, :except => {:no_release => true} do
156
+ run kill_rainbows('QUIT')
157
+ end
158
+
159
+ desc 'Immediately shutdown rainbows'
160
+ task :shutdown, :roles => rainbows_roles, :except => {:no_release => true} do
161
+ run kill_rainbows('TERM')
162
+ end
163
+
164
+ desc 'Restart rainbows'
165
+ task :restart, :roles => rainbows_roles, :except => {:no_release => true} do
166
+ run <<-END
167
+ #{duplicate_rainbows}
168
+
169
+ sleep #{rainbows_restart_sleep_time}; # in order to wait for the (old) pidfile to show up
170
+
171
+ if #{old_rainbows_is_running?}; then
172
+ #{rainbows_send_signal('QUIT', get_old_rainbows_pid)};
173
+ fi;
174
+ END
175
+ end
176
+
177
+ desc 'Duplicate rainbows'
178
+ task :duplicate, :roles => rainbows_roles, :except => {:no_release => true} do
179
+ run duplicate_rainbows()
180
+ end
181
+
182
+ desc 'Reload rainbows'
183
+ task :reload, :roles => rainbows_roles, :except => {:no_release => true} do
184
+ run <<-END
185
+ if #{rainbows_is_running?}; then
186
+ echo "Reloading rainbows...";
187
+ #{rainbows_send_signal('HUP')};
188
+ else
189
+ #{start_rainbows}
190
+ fi;
191
+ END
192
+ end
193
+
194
+ desc 'Add a new worker'
195
+ task :add_worker, :roles => rainbows_roles, :except => {:no_release => true} do
196
+ run <<-END
197
+ if #{rainbows_is_running?}; then
198
+ echo "Adding a new rainbows worker...";
199
+ #{rainbows_send_signal('TTIN')};
200
+ else
201
+ echo "rainbows is not running.";
202
+ fi;
203
+ END
204
+ end
205
+
206
+ desc 'Remove amount of workers'
207
+ task :remove_worker, :roles => rainbows_roles, :except => {:no_release => true} do
208
+ run <<-END
209
+ if #{rainbows_is_running?}; then
210
+ echo "Removing a rainbows worker...";
211
+ #{rainbows_send_signal('TTOU')};
212
+ else
213
+ echo "rainbows is not running.";
214
+ fi;
215
+ END
216
+ end
217
+ end
218
+ end
219
+ end
220
+ end
221
+ end
222
+
223
+ if Capistrano::Configuration.instance
224
+ CapistranoRainbows::CapistranoIntegration.load_into(Capistrano::Configuration.instance)
225
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-rainbows
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ben
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: capistrano
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Capistrano plugin that integrates Rainbows server tasks.
42
+ email: ben@h2ocube.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - .gitignore
48
+ - Gemfile
49
+ - LICENSE
50
+ - README.md
51
+ - Rakefile
52
+ - capistrano-rainbows.gemspec
53
+ - examples/rails3.rb
54
+ - lib/capistrano-rainbows.rb
55
+ - lib/capistrano-rainbows/capistrano_integration.rb
56
+ homepage: https://github.com/h2ocube/capistrano-rainbows
57
+ licenses: []
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.0.3
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Rainbows integration for Capistrano
79
+ test_files: []