capistrano-runit-puma 0.1.0

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: 41d1ad3edcb0ea6b5f08c8c0b86a000010358141
4
+ data.tar.gz: 5cd2de426525c85aeac0da6bad8b54c59ae14782
5
+ SHA512:
6
+ metadata.gz: 468cec02588887fba78d19a0a048f5238b97a8fa54c2340883a8397ef9bc4bf454cf17a0a7acd9fd1c57b8b8ba2482723acc5c1b8df0c6f5b0bd350c6d13260d
7
+ data.tar.gz: 5e71bcb197935816cacdede308805e38da7fd63e93ad92212e143a38c3a69fa68b3ab6dad2161c89b438bf8eded7f539b0bee8edcb0187b1926a51aca0cb9f2c
data/.gitignore ADDED
@@ -0,0 +1,23 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Alexander Simonov
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,62 @@
1
+ # capistrano-runit-puma
2
+
3
+ Capistrano3 tasks for manage puma via runit supervisor.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'capistrano-runit-puma'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install capistrano-runit-puma
18
+
19
+ ## Usage
20
+
21
+ Add this line in `Capfile`:
22
+ ```
23
+ require 'capistrano/runit/puma'
24
+ ```
25
+
26
+ ## Tasks
27
+
28
+ * `runit:puma:setup` -- setup puma runit service.
29
+ * `runit:puma:enable` -- enable and autostart service.
30
+ * `runit:puma:disable` -- stop and disable service.
31
+ * `runit:puma:start` -- start service.
32
+ * `runit:puma:stop` -- stop service.
33
+ * `runit:puma:restart` -- restart service.
34
+ * `runit:puma:phased_restart` -- run phased restart.
35
+ * `runit:puma:force_restart` -- run forced restart.
36
+
37
+ ## Variables
38
+
39
+ * `runit_puma_role` -- what host roles uses runit to run puma. Default value: `:app`
40
+ * `runit_puma_default_hooks` -- run default hooks for runit puma or not. Default value: `true`.
41
+ * `runit_puma_run_template` -- path to ERB template of `run` file. Default value: `nil`.
42
+ * `runit_puma_workers` -- number of puma workers. Default value: 1.
43
+ * `runit_puma_threads_min` -- minimal threads to use. Default value: 0.
44
+ * `runit_puma_threads_max` -- maximal threads to use. Default value: 16.
45
+ * `runit_puma_bind` -- bind URI. Examples: tcp://127.0.0.1:8080, unix:///tmp/puma.sock. Default value: nil.
46
+ * `runit_puma_rackup` -- Path to application's rackup file. Default value: `File.join(current_path, 'config.ru')`
47
+ * `runit_puma_state` -- Path to puma's state file. Default value: `File.join(shared_path, 'tmp', 'pids', 'puma.state')`
48
+ * `runit_puma_pid` -- Path to pid file. Default value: `File.join(shared_path, 'tmp', 'pids', 'puma.pid')`
49
+ * `runit_puma_bind` -- Puma's bind string. Default value: `File.join('unix://', shared_path, 'tmp', 'sockets', 'puma.sock')`
50
+ * `runit_puma_conf` -- Path to puma's config file. Default value: `File.join(shared_path, 'puma.rb')`
51
+ * `runit_puma_access_log` -- Path to puma's access log. Default value: `File.join(shared_path, 'log', 'puma_access.log')`
52
+ * `runit_puma_error_log` -- Path to puma's error log. Default value: `File.join(shared_path, 'log', 'puma_access.log')`
53
+ * `runit_puma_init_active_record` -- Enable or not establish ActiveRecord connection. Default value: `false`
54
+ * `runit_puma_preload_app` -- Preload application. Default value: `true`
55
+
56
+ ## Contributing
57
+
58
+ 1. Fork it ( https://github.com/capistrano-runit/capistrano-runit-puma/fork )
59
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
60
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
61
+ 4. Push to the branch (`git push origin my-new-feature`)
62
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "capistrano-runit-puma"
5
+ spec.version = '0.1.0'
6
+ spec.author = ['Oleksandr Simonov', 'Anton Ageev']
7
+ spec.email = ['alex@simonov.me', 'antage@gmail.com']
8
+ spec.summary = %q{Capistrano3 tasks for manage puma via runit supervisor.}
9
+ spec.description = %q{Capistrano3 tasks for manage puma via runit supervisor.}
10
+ spec.homepage = 'http://capistrano-runit.github.io'
11
+ spec.license = "MIT"
12
+
13
+ spec.files = `git ls-files -z`.split("\x0")
14
+ spec.require_paths = ["lib"]
15
+
16
+ spec.add_runtime_dependency 'capistrano-runit-core', '~> 0.1.0'
17
+ spec.add_development_dependency "bundler", "~> 1.6"
18
+ spec.add_development_dependency "rake"
19
+ end
File without changes
@@ -0,0 +1,3 @@
1
+ require 'erb'
2
+ require 'stringio'
3
+ load File.expand_path('../../tasks/puma.rake', __FILE__)
@@ -0,0 +1,150 @@
1
+ require 'capistrano/runit'
2
+ include ::Capistrano::Runit
3
+
4
+ namespace :load do
5
+ task :defaults do
6
+ set :runit_puma_role, -> { :app }
7
+ set :runit_puma_default_hooks, -> { true }
8
+ set :runit_puma_run_template, nil
9
+ set :runit_puma_workers, 1
10
+ set :runit_puma_threads_min, 0
11
+ set :runit_puma_threads_max, 16
12
+ set :runit_puma_rackup, -> { File.join(current_path, 'config.ru') }
13
+ set :runit_puma_state, -> { File.join(shared_path, 'tmp', 'pids', 'puma.state') }
14
+ set :runit_puma_pid, -> { File.join(shared_path, 'tmp', 'pids', 'puma.pid') }
15
+ set :runit_puma_bind, -> { File.join('unix://', shared_path, 'tmp', 'sockets', 'puma.sock') }
16
+ set :runit_puma_conf, -> { File.join(shared_path, 'puma.rb') }
17
+ set :runit_puma_conf_in_repo, -> { false }
18
+ set :runit_puma_access_log, -> { File.join(shared_path, 'log', 'puma_access.log') }
19
+ set :runit_puma_error_log, -> { File.join(shared_path, 'log', 'puma_error.log') }
20
+ set :runit_puma_init_active_record, false
21
+ set :runit_puma_preload_app, true
22
+ # Rbenv and RVM integration
23
+ set :rbenv_map_bins, fetch(:rbenv_map_bins).to_a.concat(%w(puma pumactl))
24
+ set :rvm_map_bins, fetch(:rvm_map_bins).to_a.concat(%w(puma pumactl))
25
+ end
26
+ end
27
+
28
+ namespace :deploy do
29
+ before :starting, :runit_check_puma_hooks do
30
+ invoke 'runit:puma:add_default_hooks' if fetch(:runit_puma_default_hooks)
31
+ end
32
+ end
33
+
34
+ namespace :runit do
35
+ namespace :puma do
36
+
37
+ def puma_enabled_service_dir
38
+ enabled_service_dir_for('puma')
39
+ end
40
+
41
+ def puma_service_dir
42
+ service_dir_for('puma')
43
+ end
44
+
45
+ def collect_puma_run_command
46
+ array = []
47
+ array << env_variables
48
+ array << "exec #{SSHKit.config.command_map[:bundle]} exec puma"
49
+ puma_conf_path = if fetch(:runit_puma_conf_in_repo)
50
+ "#{release_path}/config/puma.rb"
51
+ else
52
+ fetch(:runit_puma_conf)
53
+ end
54
+ array << "-C #{puma_conf_path}"
55
+ array.compact.join(' ')
56
+ end
57
+
58
+ def create_puma_default_conf
59
+ warn 'puma.rb NOT FOUND!'
60
+ path = File.expand_path('../../templates/puma.rb.erb', __FILE__)
61
+ if File.file?(path)
62
+ template = ERB.new(File.read(path))
63
+ stream = StringIO.new(template.result(binding))
64
+ upload! stream, "#{fetch(:runit_puma_conf)}"
65
+ info 'puma.rb generated'
66
+ end
67
+ end
68
+
69
+ task :add_default_hooks do
70
+ after 'deploy:check', 'runit:puma:check'
71
+ after 'deploy:finished', 'runit:puma:restart'
72
+ end
73
+
74
+ task :check do
75
+ check_service('puma')
76
+ on roles fetch(:runit_puma_role) do
77
+ if test "[ -d #{puma_enabled_service_dir} ]"
78
+ # Create puma.rb for new deployments if not in repo
79
+ if !fetch(:runit_puma_conf_in_repo) && !test("[ -f #{fetch(:runit_puma_conf)} ]")
80
+ create_puma_default_conf
81
+ end
82
+ else
83
+ error "Puma runit service isn't enabled."
84
+ end
85
+ end
86
+ end
87
+
88
+ desc 'Setup puma runit service'
89
+ task :setup do
90
+ # requirements
91
+ if fetch(:runit_puma_bind).nil?
92
+ $stderr.puts "You should set 'runit_puma_bind' variable."
93
+ exit 1
94
+ end
95
+ setup_service('puma', collect_sidekiq_run_command)
96
+ end
97
+
98
+ desc 'Enable puma runit service'
99
+ task :enable do
100
+ enable_service('puma')
101
+ end
102
+
103
+ desc 'Disable puma runit service'
104
+ task :disable do
105
+ disable_service('puma')
106
+ end
107
+
108
+ desc 'Start puma runit service'
109
+ task :start do
110
+ start_service('puma')
111
+ end
112
+
113
+ desc 'Stop puma runit service'
114
+ task :stop do
115
+ stop_service('puma')
116
+ end
117
+
118
+ desc 'Restart puma runit service'
119
+ task :restart do
120
+ on roles fetch(:runit_puma_role) do
121
+ if test "[ -d #{puma_enabled_service_dir} ]"
122
+ if test("[ -f #{fetch(:runit_puma_pid)} ]") && test("kill -0 $( cat #{fetch(:runit_puma_pid)} )")
123
+ within current_path do
124
+ execute :bundle, :exec, :pumactl, "-S #{fetch(:runit_puma_state)} restart"
125
+ end
126
+ else
127
+ info 'Puma is not running'
128
+ if test("[ -f #{fetch(:runit_puma_pid)} ]")
129
+ info 'Removing broken pid file'
130
+ execute :rm, '-f', fetch(:runit_puma_pid)
131
+ end
132
+ execute "#{fetch(:runit_sv_path)} start #{puma_enabled_service_dir}"
133
+ end
134
+ else
135
+ error "Puma runit service isn't enabled."
136
+ end
137
+ end
138
+ end
139
+
140
+ desc 'Force restart puma runit service'
141
+ task :force_restart do
142
+ restart_service('puma')
143
+ end
144
+
145
+ desc 'Run phased restart puma runit service'
146
+ task :phased_restart do
147
+ kill_hup_service('puma')
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,28 @@
1
+ directory '<%= current_path %>'
2
+ environment '<%= fetch(:rack_env, fetch(:rails_env, "production")) %>'
3
+ daemonize false
4
+ quiet
5
+ pidfile '<%= fetch(:runit_puma_pid)%>'
6
+ state_path '<%= fetch(:runit_puma_state)%>'
7
+ stdout_redirect '<%= fetch(:runit_puma_access_log)%>', '<%= fetch(:runit_puma_error_log)%>', true
8
+
9
+ workers <%= fetch(:runit_puma_workers, 1) %>
10
+ threads <%= fetch(:runit_puma_threads_min, 0) %>, <%= fetch(:runit_puma_threads_max, 16) %>
11
+ bind "<%= fetch(:runit_puma_bind) %>"
12
+
13
+ <% if fetch(:runit_puma_preload_app) %>
14
+ preload_app!
15
+ <% end %>
16
+
17
+ on_restart do
18
+ puts 'Refreshing Gemfile'
19
+ ENV["BUNDLE_GEMFILE"] = "<%= fetch(:bundle_gemfile, "#{current_path}/Gemfile") %>"
20
+ end
21
+
22
+ on_worker_boot do
23
+ <% if fetch(:runit_puma_init_active_record) %>
24
+ ActiveSupport.on_load(:active_record) do
25
+ ActiveRecord::Base.establish_connection
26
+ end
27
+ <% end %>
28
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-runit-puma
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Oleksandr Simonov
8
+ - Anton Ageev
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-09-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano-runit-core
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 0.1.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 0.1.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.6'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.6'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ description: Capistrano3 tasks for manage puma via runit supervisor.
57
+ email:
58
+ - alex@simonov.me
59
+ - antage@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - capistrano-runit-puma.gemspec
70
+ - lib/capistrano-runit-puma.rb
71
+ - lib/capistrano/runit/puma.rb
72
+ - lib/capistrano/tasks/puma.rake
73
+ - lib/capistrano/templates/puma.rb.erb
74
+ homepage: http://capistrano-runit.github.io
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.2.2
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Capistrano3 tasks for manage puma via runit supervisor.
98
+ test_files: []