capistrano-puma-sic 0.1.0
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 +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +53 -0
- data/Rakefile +1 -0
- data/capistrano-puma-sic.gemspec +23 -0
- data/lib/capistrano/puma/utility.rb +121 -0
- data/lib/capistrano/puma/version.rb +5 -0
- data/lib/capistrano/puma/workers.rb +1 -0
- data/lib/capistrano/puma.rb +1 -0
- data/lib/capistrano/tasks/puma.cap +63 -0
- data/lib/capistrano/tasks/workers.cap +29 -0
- data/lib/capistrano-puma-sic.rb +0 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6efff22ec3b694a67c03123f8e7ec796bf5fc206
|
4
|
+
data.tar.gz: 508957d9771c96e60e42386213bb18b04fc80369
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a0c98167aa01f468b96545bc97e0d16a828a811de7ea8b3733f905f62b8ed8d089383152c3ba6645aeb551c2a3cfe7547667732ec3245d84fe472ff80a457e60
|
7
|
+
data.tar.gz: 7a14d4abea90a012904373f8e2df17525a362a910329fa582df01d5a3d8cbff826df9715467be7d4f92ac51aae1de5a4a64688596af108fbf177216c2bb1f0de
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Florian Schwab
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
[](https://rubygems.org/gems/capistrano-puma-sic)
|
2
|
+
[](https://gemnasium.com/SICSoftwareGmbH/capistrano-puma)
|
3
|
+
[](https://codeclimate.com/github/SICSoftwareGmbH/capistrano-puma)
|
4
|
+
|
5
|
+
# Capistrano::Puma
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'capistrano-puma-sic'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install capistrano-puma-sic
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Require in `Capfile` to use the default task:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'capistrano/puma'
|
29
|
+
require 'capistrano/puma/console' # Optional: Adds worker tasks
|
30
|
+
```
|
31
|
+
|
32
|
+
Configurable options, shown here with defaults:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
set :puma_env, -> { fetch(:rack_env, fetch(:rails_env, fetch(:stage))) }
|
36
|
+
set :puma_roles, :app
|
37
|
+
set :puma_user, nil # triggers usage of sudo
|
38
|
+
set :puma_bundle, -> { fetch(:bundle_cmd, :bundle) }
|
39
|
+
set :puma_bin, :puma
|
40
|
+
set :pumactl_bin, :pumactl
|
41
|
+
set :puma_conf, -> { File.join(release_path, 'config', 'puma', "#{fetch(:stage)}.rb") }
|
42
|
+
set :puma_pid, -> { File.join(shared_path, 'tmp', 'pids', 'puma.pid') }
|
43
|
+
set :puma_state, -> { File.join(shared_path, 'tmp', 'pids', 'puma.state') }
|
44
|
+
set :puma_restart_strategy, :restart # valid values: restart, phased-restart
|
45
|
+
```
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
1. Fork it
|
50
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
51
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
52
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
53
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capistrano/puma/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'capistrano-puma-sic'
|
8
|
+
spec.version = Capistrano::Puma::VERSION
|
9
|
+
spec.authors = ['Florian Schwab']
|
10
|
+
spec.email = ['florian.schwab@sic-software.com']
|
11
|
+
spec.description = %q{Puma integration for Capistrano 3}
|
12
|
+
spec.summary = %q{Puma integration for Capistrano}
|
13
|
+
spec.homepage = 'https://github.com/SICSoftwareGmbH/capistrano-puma'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.required_ruby_version = '>= 1.9.3'
|
17
|
+
|
18
|
+
spec.files = `git ls-files`.split($/)
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'capistrano', '~> 3.4'
|
22
|
+
spec.add_dependency 'puma' , '>= 2.6'
|
23
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
module Puma
|
5
|
+
module Utility
|
6
|
+
def puma_roles
|
7
|
+
fetch(:puma_roles, :app)
|
8
|
+
end
|
9
|
+
|
10
|
+
def puma_cmd(cmd)
|
11
|
+
cmds = []
|
12
|
+
|
13
|
+
if fetch(:puma_bundle)
|
14
|
+
cmds += fetch(:puma_bundle).to_s.split(/\s+/)
|
15
|
+
cmds << 'exec'
|
16
|
+
end
|
17
|
+
|
18
|
+
cmds += fetch(cmd).to_s.split(/\s+/)
|
19
|
+
|
20
|
+
cmds.compact
|
21
|
+
end
|
22
|
+
|
23
|
+
def check_puma_config
|
24
|
+
return if puma_test "[ -f #{fetch(:puma_conf)} ]"
|
25
|
+
|
26
|
+
fail "Puma config file missing: #{fetch(:puma_conf)}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def puma_signal(sig)
|
30
|
+
#unless check_puma_pid
|
31
|
+
# fail "Puma is not running!"
|
32
|
+
#end
|
33
|
+
|
34
|
+
on roles puma_roles do
|
35
|
+
puma_execute :kill, "-#{sig}", "$( cat #{fetch(:puma_pid)} )"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def puma_execute(*args)
|
40
|
+
check_puma_config
|
41
|
+
|
42
|
+
options = args.extract_options!
|
43
|
+
|
44
|
+
command = [:bash, '-l', '-c', "\"#{args.join(' ')}\""]
|
45
|
+
|
46
|
+
within release_path do
|
47
|
+
with rack_env: fetch(:puma_env), rails_env: fetch(:puma_env) do
|
48
|
+
if puma_user = fetch(:puma_user)
|
49
|
+
execute :sudo, '-u', puma_user, command, options
|
50
|
+
else
|
51
|
+
execute *command, options
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def puma_test(*args)
|
58
|
+
options = args.extract_options!
|
59
|
+
|
60
|
+
command = [:bash, '-l', '-c', "\"#{args.join(' ')}\""]
|
61
|
+
|
62
|
+
if puma_user = fetch(:puma_user)
|
63
|
+
test :sudo, '-u', puma_user, command, options
|
64
|
+
else
|
65
|
+
test *command, options
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def check_puma_pid
|
70
|
+
return false unless test "[ -f #{fetch(:puma_pid)} ]"
|
71
|
+
|
72
|
+
unless puma_test "kill -0 $( cat #{fetch(:puma_pid)} )"
|
73
|
+
puma_execute :rm, fetch(:puma_pid)
|
74
|
+
|
75
|
+
return false
|
76
|
+
end
|
77
|
+
|
78
|
+
true
|
79
|
+
end
|
80
|
+
|
81
|
+
def start_puma
|
82
|
+
puma_execute puma_cmd(:puma_bin), "-C #{fetch(:puma_conf)}", '--daemon'
|
83
|
+
end
|
84
|
+
|
85
|
+
def stop_puma
|
86
|
+
return unless check_puma_pid
|
87
|
+
|
88
|
+
puma_execute puma_cmd(:pumactl_bin), "-S #{fetch(:puma_state)}", :stop
|
89
|
+
end
|
90
|
+
|
91
|
+
def restart_puma
|
92
|
+
if check_puma_pid
|
93
|
+
puma_execute puma_cmd(:pumactl_bin), "-S #{fetch(:puma_state)}", :restart
|
94
|
+
else
|
95
|
+
start_puma
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def phased_restart_puma
|
100
|
+
if check_puma_pid
|
101
|
+
puma_execute puma_cmd(:pumactl_bin), "-S #{fetch(:puma_state)}", 'phased-restart'
|
102
|
+
else
|
103
|
+
start_puma
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def puma_deploy_restart
|
108
|
+
restart_strategy = fetch(:puma_restart_strategy, :restart).to_s
|
109
|
+
|
110
|
+
case restart_strategy
|
111
|
+
when 'restart'
|
112
|
+
restart_puma
|
113
|
+
when 'phased-restart'
|
114
|
+
phased_restart_puma
|
115
|
+
else
|
116
|
+
fail "Invalid restart strategy: #{restart_strategy}"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path('../../tasks/workers.cap', __FILE__)
|
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path('../tasks/puma.cap', __FILE__)
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'capistrano/puma/utility'
|
2
|
+
|
3
|
+
include Capistrano::Puma::Utility
|
4
|
+
|
5
|
+
namespace :load do
|
6
|
+
task :defaults do
|
7
|
+
# Bin maps
|
8
|
+
set :rbenv_map_bins, fetch(:rbenv_map_bins).to_a.concat(%w( puma pumactl ))
|
9
|
+
set :rvm_map_bins, fetch(:rvm_map_bins).to_a.concat(%w( puma pumactl ))
|
10
|
+
|
11
|
+
# Environment
|
12
|
+
set :puma_env, -> { fetch(:rack_env, fetch(:rails_env, fetch(:stage))) }
|
13
|
+
set :puma_roles, :app
|
14
|
+
set :puma_user, nil
|
15
|
+
set :puma_bundle, -> { fetch(:bundle_cmd, :bundle) }
|
16
|
+
set :puma_bin, :puma
|
17
|
+
set :pumactl_bin, :pumactl
|
18
|
+
set :puma_conf, -> { File.join(release_path, 'config', 'puma', "#{fetch(:stage)}.rb") }
|
19
|
+
set :puma_pid, -> { File.join(shared_path, 'tmp', 'pids', 'puma.pid') }
|
20
|
+
set :puma_state, -> { File.join(shared_path, 'tmp', 'pids', 'puma.state') }
|
21
|
+
|
22
|
+
# Misc
|
23
|
+
set :puma_restart_strategy, :restart
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
namespace :puma do
|
28
|
+
desc 'Start puma'
|
29
|
+
task :start do
|
30
|
+
on roles puma_roles do
|
31
|
+
start_puma
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'Stop puma'
|
36
|
+
task :stop do
|
37
|
+
on roles puma_roles do
|
38
|
+
stop_puma
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
desc 'Restart puma'
|
43
|
+
task :restart do
|
44
|
+
on roles puma_roles do
|
45
|
+
restart_puma
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
desc 'Phased restart puma'
|
50
|
+
task :'phased-restart' do
|
51
|
+
on roles puma_roles do
|
52
|
+
phased_restart_puma
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
task :deploy_restart do
|
57
|
+
on roles puma_roles do
|
58
|
+
puma_deploy_restart
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
after 'deploy:publishing', :deploy_restart
|
63
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'capistrano/puma/utility'
|
2
|
+
|
3
|
+
include Capistrano::Puma::Utility
|
4
|
+
|
5
|
+
namespace :puma do
|
6
|
+
namespace :workers do
|
7
|
+
desc 'Number of workers'
|
8
|
+
task :count do
|
9
|
+
on roles puma_roles do |host|
|
10
|
+
check_puma_pid
|
11
|
+
|
12
|
+
pid = capture("cat #{fetch(:puma_pid)}").strip
|
13
|
+
workers_count = capture("ps ax | grep -c 'puma: cluster worker [0-9]\\+: #{pid}'").to_i
|
14
|
+
|
15
|
+
log "Workers on #{host.hostname}: #{workers_count}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'Add a worker'
|
20
|
+
task :add do
|
21
|
+
puma_signal(:TTIN)
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Remove a worker'
|
25
|
+
task :remove do
|
26
|
+
puma_signal(:TTOU)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-puma-sic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Florian Schwab
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capistrano
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: puma
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.6'
|
41
|
+
description: Puma integration for Capistrano 3
|
42
|
+
email:
|
43
|
+
- florian.schwab@sic-software.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- capistrano-puma-sic.gemspec
|
54
|
+
- lib/capistrano-puma-sic.rb
|
55
|
+
- lib/capistrano/puma.rb
|
56
|
+
- lib/capistrano/puma/utility.rb
|
57
|
+
- lib/capistrano/puma/version.rb
|
58
|
+
- lib/capistrano/puma/workers.rb
|
59
|
+
- lib/capistrano/tasks/puma.cap
|
60
|
+
- lib/capistrano/tasks/workers.cap
|
61
|
+
homepage: https://github.com/SICSoftwareGmbH/capistrano-puma
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 1.9.3
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.4.6
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Puma integration for Capistrano
|
85
|
+
test_files: []
|