capistrano-puma-simple 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 650914f5ac733277163d698a04666d4d645b063c
4
+ data.tar.gz: 597cbbaac95d8df23b8228d49bd59a10bee48cdd
5
+ SHA512:
6
+ metadata.gz: 87516c16ed5b310896f1e51b394fb2582c2ddcc99ce8772a86ebbdad9ace2113edc073707af57e1dcbc775b5b4da68b0c650672265c8cd70c3259e2e926f8724
7
+ data.tar.gz: b969599b4631222c2f2d391f7138458b9d4e289cf5dca3e8039ce5b831c8d68a05865497b5a79b0c634d6f06fb38907ce67f5ab6e6e8bc307d9811451d2ac549
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rubocop.yml ADDED
@@ -0,0 +1,60 @@
1
+ AllCops:
2
+ Exclude:
3
+ - "vendor/**/*"
4
+ DisplayCopNames: true
5
+
6
+ Style/AsciiComments:
7
+ Enabled: false
8
+
9
+ Style/BracesAroundHashParameters:
10
+ Enabled: false
11
+
12
+ Style/Documentation:
13
+ Enabled: false
14
+
15
+ Style/ExtraSpacing:
16
+ Enabled: false
17
+
18
+ Style/GuardClause:
19
+ MinBodyLength: 5
20
+
21
+ Style/MethodDefParentheses:
22
+ EnforcedStyle: require_parentheses
23
+
24
+ Style/ModuleFunction:
25
+ Enabled: false
26
+
27
+ Style/StringLiterals:
28
+ EnforcedStyle: double_quotes
29
+
30
+ Style/SingleSpaceBeforeFirstArg:
31
+ Enabled: false
32
+
33
+ Style/IndentationConsistency:
34
+ EnforcedStyle: rails
35
+
36
+ Style/SignalException:
37
+ EnforcedStyle: only_raise
38
+
39
+ Style/HashSyntax:
40
+ EnforcedStyle: ruby19_no_mixed_keys
41
+ Exclude:
42
+ - "**/*.rake"
43
+ - "Rakefile"
44
+
45
+ Metrics/LineLength:
46
+ Max: 160
47
+ Exclude:
48
+ - "db/migrate/*.rb"
49
+
50
+ NumericLiterals:
51
+ MinDigits: 7
52
+
53
+ Lint/AssignmentInCondition:
54
+ Enabled: false
55
+
56
+ Lint/BlockAlignment:
57
+ Enabled: false
58
+
59
+ Metrics/MethodLength:
60
+ Max: 12
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in capistrano-puma-simple.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 hirocaster
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,75 @@
1
+ # Capistrano::PumaSimple
2
+
3
+ Puma control by Capistrano
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'capistrano-puma-simple'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install capistrano-puma-simple
18
+
19
+ ## Usage
20
+
21
+ ```
22
+ # in Capfile
23
+ require "capistrano/puma-simple"
24
+
25
+ ```
26
+
27
+ then you can use `cap -T` to list tasks
28
+
29
+ ```
30
+ cap puma:config # Setup puma config file
31
+ cap puma:halt # Halt puma
32
+ cap puma:phased-restart # Phased-restart puma
33
+ cap puma:restart # Restart puma
34
+ cap puma:start # Start puma
35
+ cap puma:status # Status puma
36
+ cap puma:stop # Stop puma
37
+ cap puma:template # Export template file
38
+ ```
39
+
40
+ you may want to customize `puma.rb` export template file
41
+
42
+ ```
43
+ cap puma:template # Export template file
44
+ ``
45
+
46
+ customize to `config/deploy/templates/puma.rb.erb`
47
+
48
+ Configurable options, shown here with defaults:
49
+
50
+ ```
51
+ set :puma_role, :app
52
+ set :puma_env, -> { fetch(:rack_env, fetch(:rails_env, fetch(:stage))) }
53
+ set :puma_rackup, -> { File.join(current_path, "config.ru") }
54
+ set :puma_conf, -> { File.join(shared_path, "puma.rb") }
55
+ set :puma_pid, -> { File.join(shared_path, "tmp", "pids", "puma.pid") }
56
+ set :puma_state, -> { File.join(shared_path, "tmp", "pids", "puma.state") }
57
+ set :puma_access_log, -> { File.join(shared_path, "log", "puma_access.log") }
58
+ set :puma_error_log, -> { File.join(shared_path, "log", "puma_error.log") }
59
+ set :puma_threads, [0, 16]
60
+ set :puma_workers, 0
61
+ set :puma_bind, "tcp://0.0.0.0:9292"
62
+ set :puma_default_control_app, -> { File.join("unix://#{shared_path}", "tmp", "sockets", "pumactl.sock") }
63
+ set :puma_tag, -> { fetch(:application) }
64
+ set :puma_worker_timeout, 60
65
+ set :puma_init_active_record, false
66
+ set :puma_preload_app, false
67
+ ```
68
+
69
+ ## Contributing
70
+
71
+ 1. Fork it
72
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
73
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
74
+ 4. Push to the branch (`git push origin my-new-feature`)
75
+ 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-simple/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "capistrano-puma-simple"
8
+ spec.version = Capistrano::PumaSimple::VERSION
9
+ spec.authors = ["hirocaster"]
10
+ spec.email = ["hohtsuka@gmail.com"]
11
+ spec.description = "Puma simple integration for Capistrano3"
12
+ spec.summary = "Puma simple integration for Capistrano3"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module PumaSimple
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ load File.expand_path('../tasks/puma.rake', __FILE__)
@@ -0,0 +1,180 @@
1
+ namespace :load do
2
+ task :defaults do
3
+ set :puma_default_hooks, true
4
+ set :puma_role, :app
5
+ set :puma_env, -> { fetch(:rack_env, fetch(:rails_env, fetch(:stage))) }
6
+ set :puma_rackup, -> { File.join(current_path, "config.ru") }
7
+ set :puma_conf, -> { File.join(shared_path, "puma.rb") }
8
+ set :puma_pid, -> { File.join(shared_path, "tmp", "pids", "puma.pid") }
9
+ set :puma_state, -> { File.join(shared_path, "tmp", "pids", "puma.state") }
10
+ set :puma_access_log, -> { File.join(shared_path, "log", "puma_access.log") }
11
+ set :puma_error_log, -> { File.join(shared_path, "log", "puma_error.log") }
12
+ set :puma_threads, [0, 16]
13
+ set :puma_workers, 0
14
+ set :puma_bind, "tcp://0.0.0.0:9292"
15
+ set :puma_default_control_app, -> { File.join("unix://#{shared_path}", "tmp", "sockets", "pumactl.sock") }
16
+ set :puma_tag, -> { fetch(:application) }
17
+ set :puma_worker_timeout, 60
18
+ set :puma_init_active_record, false
19
+ set :puma_preload_app, false
20
+ end
21
+ end
22
+
23
+ namespace :deploy do
24
+ before :starting, :check_puma_hooks do
25
+ invoke "puma:add_default_hooks" if fetch(:puma_default_hooks)
26
+ end
27
+ end
28
+
29
+ namespace :puma do
30
+ task :add_default_hooks do
31
+ after "deploy:check", "puma:check"
32
+ after "deploy:finished", "puma:smart_restart"
33
+ end
34
+
35
+ task :check do
36
+ on roles fetch(:puma_role) do |_role|
37
+ unless test "[ -f #{fetch(:puma_conf)} ]"
38
+ warn "puma.rb NOT FOUND!"
39
+ invoke "puma:config"
40
+ info "puma.rb generated"
41
+ end
42
+ end
43
+ end
44
+
45
+ desc "Export template file"
46
+ task :template do
47
+ FileUtils.mkdir_p "config/deploy/templates/" unless File.exist? "config/deploy/templates/"
48
+ FileUtils.cp File.expand_path("../../templates/puma.rb.erb", __FILE__), "config/deploy/templates/puma.rb.erb"
49
+ end
50
+
51
+ desc "Setup puma config file"
52
+ task :config do
53
+ on roles(fetch(:puma_role)) do |role|
54
+ template_puma role
55
+ end
56
+ end
57
+
58
+ desc "Start puma"
59
+ task :start do
60
+ on roles fetch(:puma_role) do |role|
61
+ puma_switch_user(role) do
62
+ if test "[ -f #{fetch(:puma_conf)} ]"
63
+ info "using conf file #{fetch(:puma_conf)}"
64
+ else
65
+ invoke "puma:config"
66
+ end
67
+ within current_path do
68
+ with rack_env: fetch(:puma_env) do
69
+ execute :bundle, :exec, :puma, "-C #{fetch(:puma_conf)} --daemon"
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ %w(halt stop status).map do |command|
77
+ desc "#{command.capitalize} puma"
78
+ task command do
79
+ on roles fetch(:puma_role) do |role|
80
+ within current_path do
81
+ puma_switch_user(role) do
82
+ with rack_env: fetch(:puma_env) do
83
+ if test "[ -f #{fetch(:puma_pid)} ]"
84
+ if test :kill, "-0 $( cat #{fetch(:puma_pid)} )"
85
+ execute :bundle, :exec, :pumactl, "-S #{fetch(:puma_state)} -F #{fetch(:puma_conf)} #{command}"
86
+ else
87
+ # delete invalid pid file , process is not running.
88
+ execute :rm, fetch(:puma_pid)
89
+ end
90
+ else
91
+ # pid file not found, so puma is probably not running or it using another pidfile
92
+ warn "Puma not running"
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ %w(phased-restart restart).map do |command|
102
+ desc "#{command.capitalize} puma"
103
+ task command do
104
+ on roles fetch(:puma_role) do |role|
105
+ within current_path do
106
+ puma_switch_user(role) do
107
+ with rack_env: fetch(:puma_env) do
108
+ if (test "[ -f #{fetch(:puma_pid)} ]") && (test :kill, "-0 $( cat #{fetch(:puma_pid)} )")
109
+ # NOTE pid exist but state file is nonsense, so ignore that case
110
+ execute :bundle, :exec, :pumactl, "-S #{fetch(:puma_state)} -F #{fetch(:puma_conf)} #{command}"
111
+ else
112
+ # Puma is not running or state file is not present : Run it
113
+ invoke "puma:start"
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
121
+
122
+ task :smart_restart do
123
+ if !fetch(:puma_preload_app) && fetch(:puma_workers).to_i > 1
124
+ invoke "puma:phased-restart"
125
+ else
126
+ invoke "puma:restart"
127
+ end
128
+ end
129
+
130
+ def puma_bind
131
+ Array(fetch(:puma_bind)).collect do |bind|
132
+ "bind '#{bind}'"
133
+ end.join("\n")
134
+ end
135
+
136
+ def puma_switch_user(role, &block)
137
+ user = puma_user(role)
138
+ if user == role.user
139
+ block.call
140
+ else
141
+ as user do
142
+ block.call
143
+ end
144
+ end
145
+ end
146
+
147
+ def puma_user(role)
148
+ properties = role.properties
149
+ properties.fetch(:puma_user) || # local property for puma only
150
+ fetch(:puma_user) ||
151
+ properties.fetch(:run_as) || # global property across multiple capistrano gems
152
+ role.user
153
+ end
154
+
155
+ def template_puma(role)
156
+ templates_path(role).each do |path|
157
+ if File.file? path
158
+ erb = File.read path
159
+ upload! StringIO.new(ERB.new(erb).result(binding)), fetch(:puma_conf)
160
+ break
161
+ else
162
+ next
163
+ end
164
+ end
165
+ end
166
+
167
+ def templates_path(role)
168
+ [
169
+ "config/deploy/templates/puma-#{fetch(:stage)}-#{role.hostname}.rb.erb",
170
+ "config/deploy/templates/puma-#{role.hostname}.rb.erb",
171
+ "config/deploy/templates/puma-#{fetch(:stage)}.rb.erb",
172
+ "config/deploy/templates/puma.rb.erb",
173
+ "lib/capistrano/templates/puma-#{fetch(:stage)}-#{role.hostname}.rb.erb",
174
+ "lib/capistrano/templates/puma-#{role.hostname}.rb.erb",
175
+ "lib/capistrano/templates/puma-#{fetch(:stage)}.rb.erb",
176
+ "lib/capistrano/templates/puma.rb.erb",
177
+ File.expand_path("../../templates/puma.rb.erb", __FILE__)
178
+ ]
179
+ end
180
+ end
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env puma
2
+
3
+ directory '<%= current_path %>'
4
+ rackup "<%=fetch(:puma_rackup)%>"
5
+ environment '<%= fetch(:puma_env) %>'
6
+ <% if fetch(:puma_tag) %>
7
+ tag '<%= fetch(:puma_tag)%>'
8
+ <% end %>
9
+ pidfile "<%=fetch(:puma_pid)%>"
10
+ state_path "<%=fetch(:puma_state)%>"
11
+ stdout_redirect '<%=fetch(:puma_access_log)%>', '<%=fetch(:puma_error_log)%>', true
12
+
13
+
14
+ threads <%=fetch(:puma_threads).join(',')%>
15
+
16
+ <%= puma_bind %>
17
+ <% if fetch(:puma_control_app) %>
18
+ activate_control_app "<%= fetch(:puma_default_control_app) %>"
19
+ <% end %>
20
+ workers <%= fetch(:puma_workers) %>
21
+ <% if fetch(:puma_worker_timeout) %>
22
+ worker_timeout <%= fetch(:puma_worker_timeout).to_i %>
23
+ <% end %>
24
+
25
+ <% if fetch(:puma_preload_app) %>
26
+ preload_app!
27
+ <% else %>
28
+ prune_bundler
29
+ <% end %>
30
+
31
+ on_restart do
32
+ puts 'Refreshing Gemfile'
33
+ ENV["BUNDLE_GEMFILE"] = "<%= fetch(:bundle_gemfile, "#{current_path}/Gemfile") %>"
34
+ end
35
+
36
+ <% if fetch(:puma_preload_app) && fetch(:puma_init_active_record) %>
37
+ on_worker_boot do
38
+ ActiveSupport.on_load(:active_record) do
39
+ ActiveRecord::Base.establish_connection
40
+ end
41
+ end
42
+ <% end %>
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-puma-simple
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - hirocaster
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Puma simple integration for Capistrano3
42
+ email:
43
+ - hohtsuka@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rubocop.yml"
50
+ - ".ruby-version"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - capistrano-puma-simple.gemspec
56
+ - lib/capistrano/puma-simple.rb
57
+ - lib/capistrano/puma-simple/version.rb
58
+ - lib/capistrano/tasks/puma.rake
59
+ - lib/capistrano/templates/puma.rb.erb
60
+ homepage: ''
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.5.0
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Puma simple integration for Capistrano3
84
+ test_files: []