capistrano3-puma 5.2.0 → 6.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/LICENSE.txt +1 -1
- data/README.md +10 -145
- data/lib/capistrano/puma/systemd.rb +11 -6
- data/lib/capistrano/puma.rb +16 -58
- data/lib/capistrano/tasks/systemd.rake +64 -61
- data/lib/capistrano/templates/puma.service.erb +26 -14
- data/lib/generators/capistrano/nginx_puma/config_generator.rb +0 -1
- metadata +12 -33
- data/.github/workflows/stale.yml +0 -19
- data/.gitignore +0 -18
- data/CONTRIBUTORS.md +0 -48
- data/Gemfile +0 -8
- data/Rakefile +0 -9
- data/capistrano3-puma.gemspec +0 -28
- data/lib/capistrano/puma/daemon.rb +0 -13
- data/lib/capistrano/puma/jungle.rb +0 -22
- data/lib/capistrano/puma/monit.rb +0 -34
- data/lib/capistrano/puma/version.rb +0 -5
- data/lib/capistrano/puma/workers.rb +0 -9
- data/lib/capistrano/tasks/daemon.rake +0 -74
- data/lib/capistrano/tasks/jungle.rake +0 -65
- data/lib/capistrano/tasks/monit.rake +0 -61
- data/lib/capistrano/tasks/puma.rake +0 -21
- data/lib/capistrano/tasks/workers.rake +0 -43
- data/lib/capistrano/templates/puma-deb.erb +0 -421
- data/lib/capistrano/templates/puma-rpm.erb +0 -328
- data/lib/capistrano/templates/puma.rb.erb +0 -54
- data/lib/capistrano/templates/puma_monit.conf.erb +0 -7
- data/lib/capistrano/templates/run-puma.erb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d2f6376b7e7c2838e8d06d7acb249e7b4cca75982bd440e2ad8952f80941132
|
4
|
+
data.tar.gz: 24ca957bc88c4f06d7a11dea7c70b72f77ca275bc46a77b6eb44f98bc51b5a3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0d445a032ad196fd65b8aa863c1fb049aec6f9e8f47f22cd2d05993555c354e110bfb397d1a001b6ee0b3cb9b19e38c3d6fe76bba47d5682b17992910a5717c
|
7
|
+
data.tar.gz: 9bba6960b9246b4877b02baa6339baf7a940caf16bcf54be2c0148850f96b7af1e68a07a97d03ac07bbc978275e1ea6ca44812587da942e176b674d230d2a88c
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
[Unreleased](https://github.com/seuros/capistrano-puma/compare/v5.2.0...master)
|
4
|
+
- Removed support for support for monit and upstart. (will add them back if someone is willing to maintain them)
|
5
|
+
- Sync configuration with capistrano-sidekiq
|
6
|
+
- Support for notify systemd service. Add sd_notify gem to your Gemfile.
|
7
|
+
- Add example application for easier testing.
|
8
|
+
- Deprecate Nginx support. (configuration tools should be preferred over capistrano tasks)
|
9
|
+
|
3
10
|
## [5.2.0](https://github.com/seuros/capistrano-puma/tree/5.2.0) (2021-09-11)
|
4
11
|
|
5
12
|
[Full Changelog](https://github.com/seuros/capistrano-puma/compare/v5.1.1...5.2.0)
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -21,27 +21,14 @@ And then execute:
|
|
21
21
|
|
22
22
|
require 'capistrano/puma'
|
23
23
|
install_plugin Capistrano::Puma # Default puma tasks
|
24
|
-
install_plugin Capistrano::Puma::
|
25
|
-
install_plugin Capistrano::Puma::Jungle # if you need the jungle tasks
|
26
|
-
install_plugin Capistrano::Puma::Monit # if you need the monit tasks
|
27
|
-
install_plugin Capistrano::Puma::Nginx # if you want to upload a nginx site template
|
28
|
-
```
|
29
|
-
You will need to select your service manager
|
30
|
-
```ruby
|
31
|
-
install_plugin Capistrano::Puma::Daemon # If you using puma daemonized (not supported in Puma 5+)
|
32
|
-
```
|
33
|
-
or
|
34
|
-
```ruby
|
35
|
-
install_plugin Capistrano::Puma::Systemd # if you use SystemD
|
24
|
+
install_plugin Capistrano::Puma::Systemd
|
36
25
|
```
|
37
26
|
|
38
27
|
To prevent loading the hooks of the plugin, add false to the load_hooks param.
|
39
28
|
```ruby
|
40
29
|
# Capfile
|
41
30
|
|
42
|
-
require 'capistrano/puma'
|
43
31
|
install_plugin Capistrano::Puma, load_hooks: false # Default puma tasks without hooks
|
44
|
-
install_plugin Capistrano::Puma::Monit, load_hooks: false # Monit tasks without hooks
|
45
32
|
```
|
46
33
|
|
47
34
|
To make it work with rvm, rbenv and chruby, install the plugin after corresponding library inclusion.
|
@@ -55,84 +42,12 @@ To make it work with rvm, rbenv and chruby, install the plugin after correspondi
|
|
55
42
|
|
56
43
|
### Config
|
57
44
|
|
58
|
-
|
59
|
-
|
60
|
-
To upload puma config use:
|
61
|
-
```ruby
|
62
|
-
cap production puma:config
|
63
|
-
```
|
64
|
-
By default the file located in `shared/puma.rb`
|
65
|
-
|
66
|
-
|
67
|
-
Ensure that `tmp/pids` and ` tmp/sockets log` are shared (via `linked_dirs`):
|
68
|
-
|
69
|
-
`This step is mandatory before deploying, otherwise puma server won't start`
|
70
|
-
|
71
|
-
### Nginx
|
72
|
-
|
73
|
-
To upload a nginx site config (eg. /etc/nginx/sites-enabled/) use:
|
74
|
-
```ruby
|
75
|
-
cap production puma:nginx_config
|
76
|
-
```
|
77
|
-
|
78
|
-
To customize these two templates locally before uploading use:
|
79
|
-
```
|
80
|
-
rails g capistrano:nginx_puma:config
|
81
|
-
```
|
82
|
-
|
83
|
-
if your nginx server configuration is not located in `/etc/nginx`, you may need to customize:
|
84
|
-
```ruby
|
85
|
-
set :nginx_sites_available_path, "/etc/nginx/sites-available"
|
86
|
-
set :nginx_sites_enabled_path, "/etc/nginx/sites-enabled"
|
87
|
-
```
|
88
|
-
|
89
|
-
By default, `nginx_config` will be executed with `:web` role. But you can assign it to a different role:
|
90
|
-
```ruby
|
91
|
-
set :puma_nginx, :foo
|
92
|
-
```
|
93
|
-
or define a standalone one:
|
94
|
-
```ruby
|
95
|
-
role :puma_nginx, %w{root@example.com}
|
96
|
-
```
|
97
|
-
|
98
|
-
### Jungle
|
45
|
+
Puma configuration is expected to be in `config/puma.rb` or `config/puma/#{fetch(:puma_env)}.rb` and checked in your repository.
|
46
|
+
Uploading the configuration via capistrano was removed as it was causing problems with custom configurations.
|
99
47
|
|
100
|
-
|
101
|
-
```ruby
|
102
|
-
set :puma_jungle_conf, '/etc/puma.conf'
|
103
|
-
set :puma_run_path, '/usr/local/bin/run-puma'
|
104
|
-
```
|
105
|
-
|
106
|
-
### Systemd
|
107
|
-
|
108
|
-
Install Systemd plugin in `Capfile`:
|
109
|
-
```ruby
|
110
|
-
install_plugin Capistrano::Puma
|
111
|
-
install_plugin Capistrano::Puma::Systemd
|
112
|
-
```
|
113
|
-
|
114
|
-
To generate unit file use:
|
115
|
-
```
|
116
|
-
cap production puma:systemd:config puma:systemd:enable
|
117
|
-
```
|
48
|
+
## Example
|
118
49
|
|
119
|
-
|
120
|
-
|
121
|
-
```ruby
|
122
|
-
set :puma_service_unit_env_file, '/etc/environment'
|
123
|
-
```
|
124
|
-
```ruby
|
125
|
-
set :puma_service_unit_env_vars, %w[
|
126
|
-
RAILS_ENV=development
|
127
|
-
PUMA_METRICS_HTTP=tcp://0.0.0.0:9393
|
128
|
-
]
|
129
|
-
```
|
130
|
-
|
131
|
-
To use [phased restart](https://github.com/puma/puma/blob/master/docs/restart.md) for zero downtime deployments:
|
132
|
-
|
133
|
-
```ruby
|
134
|
-
set :puma_phased_restart, true
|
135
|
-
```
|
50
|
+
A sample application is provided to show how to use this gem at https://github.com/seuros/capistrano-example-app
|
136
51
|
|
137
52
|
### Systemd Socket Activation
|
138
53
|
|
@@ -150,68 +65,15 @@ cap puma:systemd:restart_socket
|
|
150
65
|
```
|
151
66
|
This would also restart the puma instance as the puma service depends on the socket service being active
|
152
67
|
|
153
|
-
### Multi bind
|
154
|
-
|
155
|
-
Multi-bind can be set with an array in the puma_bind variable
|
156
|
-
```ruby
|
157
|
-
set :puma_bind, %w(tcp://0.0.0.0:9292 unix:///tmp/puma.sock)
|
158
|
-
```
|
159
|
-
* Listening on tcp://0.0.0.0:9292
|
160
|
-
* Listening on unix:///tmp/puma.sock
|
161
|
-
|
162
|
-
### Active Record
|
163
|
-
|
164
|
-
For ActiveRecord the following line to your deploy.rb
|
165
|
-
```ruby
|
166
|
-
set :puma_init_active_record, true
|
167
|
-
```
|
168
|
-
|
169
68
|
### Other configs
|
170
69
|
|
171
70
|
Configurable options, shown here with defaults: Please note the configuration options below are not required unless you are trying to override a default setting, for instance if you are deploying on a host on which you do not have sudo or root privileges and you need to restrict the path. These settings go in the deploy.rb file.
|
172
71
|
|
173
72
|
```ruby
|
174
73
|
set :puma_user, fetch(:user)
|
175
|
-
set :
|
176
|
-
set :
|
177
|
-
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
|
178
|
-
set :puma_bind, "unix://#{shared_path}/tmp/sockets/puma.sock" #accept array for multi-bind
|
179
|
-
set :puma_control_app, false
|
180
|
-
set :puma_default_control_app, "unix://#{shared_path}/tmp/sockets/pumactl.sock"
|
181
|
-
set :puma_conf, "#{shared_path}/puma.rb"
|
182
|
-
set :puma_access_log, "#{shared_path}/log/puma_access.log"
|
183
|
-
set :puma_error_log, "#{shared_path}/log/puma_error.log"
|
184
|
-
set :puma_role, :app
|
185
|
-
set :puma_env, fetch(:rack_env, fetch(:rails_env, 'production'))
|
186
|
-
set :puma_threads, [0, 16]
|
187
|
-
set :puma_workers, 0
|
188
|
-
set :puma_worker_timeout, nil
|
189
|
-
set :puma_init_active_record, false
|
190
|
-
set :puma_preload_app, false
|
191
|
-
set :puma_daemonize, false
|
192
|
-
set :puma_plugins, [] #accept array of plugins
|
193
|
-
set :puma_tag, fetch(:application)
|
194
|
-
set :puma_restart_command, 'bundle exec puma'
|
195
|
-
set :puma_service_unit_name, "puma_#{fetch(:application)}_#{fetch(:stage)}"
|
196
|
-
set :puma_systemctl_user, :system # accepts :user
|
197
|
-
set :puma_enable_lingering, fetch(:puma_systemctl_user) != :system # https://wiki.archlinux.org/index.php/systemd/User#Automatic_start-up_of_systemd_user_instances
|
198
|
-
set :puma_lingering_user, fetch(:user)
|
199
|
-
set :puma_service_unit_env_file, nil
|
74
|
+
set :puma_role, :web
|
75
|
+
set :puma_service_unit_env_files, []
|
200
76
|
set :puma_service_unit_env_vars, []
|
201
|
-
set :puma_phased_restart, false
|
202
|
-
|
203
|
-
set :nginx_config_name, "#{fetch(:application)}_#{fetch(:stage)}"
|
204
|
-
set :nginx_flags, 'fail_timeout=0'
|
205
|
-
set :nginx_http_flags, fetch(:nginx_flags)
|
206
|
-
set :nginx_server_name, "localhost #{fetch(:application)}.local"
|
207
|
-
set :nginx_sites_available_path, '/etc/nginx/sites-available'
|
208
|
-
set :nginx_sites_enabled_path, '/etc/nginx/sites-enabled'
|
209
|
-
set :nginx_socket_flags, fetch(:nginx_flags)
|
210
|
-
set :nginx_ssl_certificate, "/etc/ssl/certs/#{fetch(:nginx_config_name)}.crt"
|
211
|
-
set :nginx_ssl_certificate_key, "/etc/ssl/private/#{fetch(:nginx_config_name)}.key"
|
212
|
-
set :nginx_use_ssl, false
|
213
|
-
set :nginx_use_http2, true
|
214
|
-
set :nginx_downstream_uses_ssl, false
|
215
77
|
```
|
216
78
|
|
217
79
|
__Notes:__ If you are setting values for variables that might be used by other plugins, use `append` instead of `set`. For example:
|
@@ -219,6 +81,9 @@ __Notes:__ If you are setting values for variables that might be used by other p
|
|
219
81
|
append :rbenv_map_bins, 'puma', 'pumactl'
|
220
82
|
```
|
221
83
|
|
84
|
+
# Nginx documentation
|
85
|
+
Nginx documentation was moved to [nginx.md](docs/nginx.md)
|
86
|
+
|
222
87
|
## Contributing
|
223
88
|
|
224
89
|
1. Fork it
|
@@ -11,13 +11,18 @@ module Capistrano
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def set_defaults
|
14
|
-
set_if_empty :puma_systemctl_bin, '/bin/systemctl'
|
15
|
-
set_if_empty :puma_service_unit_name, -> { "
|
16
|
-
set_if_empty :puma_enable_socket_service,
|
17
|
-
|
14
|
+
set_if_empty :puma_systemctl_bin, -> { fetch(:systemctl_bin, '/bin/systemctl') }
|
15
|
+
set_if_empty :puma_service_unit_name, -> { "#{fetch(:application)}_puma_#{fetch(:stage)}" }
|
16
|
+
set_if_empty :puma_enable_socket_service, false
|
17
|
+
|
18
|
+
set_if_empty :puma_service_unit_env_files, -> { fetch(:service_unit_env_files, []) }
|
19
|
+
set_if_empty :puma_service_unit_env_vars, -> { fetch(:service_unit_env_vars, []) }
|
20
|
+
|
21
|
+
set_if_empty :puma_systemctl_user, -> { fetch(:systemctl_user, :user) }
|
18
22
|
set_if_empty :puma_enable_lingering, -> { fetch(:puma_systemctl_user) != :system }
|
19
|
-
set_if_empty :puma_lingering_user, -> { fetch(:user) }
|
20
|
-
|
23
|
+
set_if_empty :puma_lingering_user, -> { fetch(:lingering_user, fetch(:user)) }
|
24
|
+
|
25
|
+
set_if_empty :puma_service_templates_path, fetch(:service_templates_path, 'config/deploy/templates')
|
21
26
|
end
|
22
27
|
|
23
28
|
def expanded_bundle_command
|
data/lib/capistrano/puma.rb
CHANGED
@@ -28,6 +28,15 @@ module Capistrano
|
|
28
28
|
end.join("\n")
|
29
29
|
end
|
30
30
|
|
31
|
+
def service_unit_type
|
32
|
+
## Jruby don't support notify
|
33
|
+
return "simple" if RUBY_ENGINE == "jruby"
|
34
|
+
fetch(:puma_service_unit_type,
|
35
|
+
## Check if sd_notify is available in the bundle
|
36
|
+
Gem::Specification.find_all_by_name("sd_notify").any? ? "notify" : "simple")
|
37
|
+
|
38
|
+
end
|
39
|
+
|
31
40
|
def compiled_template_puma(from, role)
|
32
41
|
@role = role
|
33
42
|
file = [
|
@@ -44,7 +53,7 @@ module Capistrano
|
|
44
53
|
File.expand_path("../templates/#{from}.rb.erb", __FILE__)
|
45
54
|
].detect { |path| File.file?(path) }
|
46
55
|
erb = File.read(file)
|
47
|
-
StringIO.new(ERB.new(erb,
|
56
|
+
StringIO.new(ERB.new(erb, trim_mode: '-').result(binding))
|
48
57
|
end
|
49
58
|
|
50
59
|
def template_puma(from, to, role)
|
@@ -94,72 +103,21 @@ module Capistrano
|
|
94
103
|
class Puma < Capistrano::Plugin
|
95
104
|
include PumaCommon
|
96
105
|
|
97
|
-
def define_tasks
|
98
|
-
eval_rakefile File.expand_path('../tasks/puma.rake', __FILE__)
|
99
|
-
end
|
100
|
-
|
101
106
|
def set_defaults
|
102
|
-
set_if_empty :puma_role, :
|
107
|
+
set_if_empty :puma_role, :web
|
103
108
|
set_if_empty :puma_env, -> { fetch(:rack_env, fetch(:rails_env, fetch(:stage))) }
|
104
|
-
|
105
|
-
|
106
|
-
set_if_empty :puma_threads, [0, 16]
|
107
|
-
set_if_empty :puma_workers, 0
|
108
|
-
set_if_empty :puma_rackup, -> { File.join(current_path, 'config.ru') }
|
109
|
-
set_if_empty :puma_state, -> { File.join(shared_path, 'tmp', 'pids', 'puma.state') }
|
110
|
-
set_if_empty :puma_pid, -> { File.join(shared_path, 'tmp', 'pids', 'puma.pid') }
|
111
|
-
set_if_empty :puma_bind, -> { File.join("unix://#{shared_path}", 'tmp', 'sockets', 'puma.sock') }
|
112
|
-
set_if_empty :puma_control_app, false
|
113
|
-
set_if_empty :puma_default_control_app, -> { File.join("unix://#{shared_path}", 'tmp', 'sockets', 'pumactl.sock') }
|
114
|
-
set_if_empty :puma_conf, -> { File.join(shared_path, 'puma.rb') }
|
115
|
-
set_if_empty :puma_access_log, -> { File.join(shared_path, 'log', 'puma_access.log') }
|
116
|
-
set_if_empty :puma_error_log, -> { File.join(shared_path, 'log', 'puma_error.log') }
|
117
|
-
set_if_empty :puma_init_active_record, false
|
118
|
-
set_if_empty :puma_preload_app, false
|
119
|
-
set_if_empty :puma_daemonize, false
|
120
|
-
set_if_empty :puma_tag, ''
|
121
|
-
set_if_empty :puma_restart_command, 'bundle exec puma'
|
109
|
+
set_if_empty :puma_access_log, -> { File.join(shared_path, 'log', "puma.log") }
|
110
|
+
set_if_empty :puma_error_log, -> { File.join(shared_path, 'log', "puma.log") }
|
122
111
|
|
123
112
|
# Chruby, Rbenv and RVM integration
|
124
|
-
append :chruby_map_bins, 'puma', 'pumactl'
|
125
|
-
append :rbenv_map_bins, 'puma', 'pumactl'
|
126
|
-
append :rvm_map_bins, 'puma', 'pumactl'
|
113
|
+
append :chruby_map_bins, 'puma', 'pumactl' if fetch(:chruby_map_bins)
|
114
|
+
append :rbenv_map_bins, 'puma', 'pumactl' if fetch(:rbenv_map_bins)
|
115
|
+
append :rvm_map_bins, 'puma', 'pumactl' if fetch(:rvm_map_bins)
|
127
116
|
|
128
117
|
# Bundler integration
|
129
118
|
append :bundle_bins, 'puma', 'pumactl'
|
130
119
|
end
|
131
|
-
|
132
|
-
def register_hooks
|
133
|
-
after 'deploy:check', 'puma:check'
|
134
|
-
end
|
135
|
-
|
136
|
-
def puma_workers
|
137
|
-
fetch(:puma_workers, 0)
|
138
|
-
end
|
139
|
-
|
140
|
-
def puma_preload_app?
|
141
|
-
fetch(:puma_preload_app)
|
142
|
-
end
|
143
|
-
|
144
|
-
def puma_daemonize?
|
145
|
-
fetch(:puma_daemonize)
|
146
|
-
end
|
147
|
-
|
148
|
-
def puma_plugins
|
149
|
-
Array(fetch(:puma_plugins)).collect do |bind|
|
150
|
-
"plugin '#{bind}'"
|
151
|
-
end.join("\n")
|
152
|
-
end
|
153
|
-
|
154
|
-
def upload_puma_rb(role)
|
155
|
-
template_puma 'puma', fetch(:puma_conf), role
|
156
|
-
end
|
157
120
|
end
|
158
121
|
end
|
159
122
|
|
160
|
-
require 'capistrano/puma/workers'
|
161
|
-
require 'capistrano/puma/daemon'
|
162
123
|
require 'capistrano/puma/systemd'
|
163
|
-
require 'capistrano/puma/monit'
|
164
|
-
require 'capistrano/puma/jungle'
|
165
|
-
require 'capistrano/puma/nginx'
|
@@ -3,76 +3,65 @@
|
|
3
3
|
git_plugin = self
|
4
4
|
|
5
5
|
namespace :puma do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
execute :mv, "#{fetch(:tmp_dir)}/#{unit_filename}", "#{systemd_path}"
|
19
|
-
end
|
6
|
+
desc 'Install Puma systemd service'
|
7
|
+
task :install do
|
8
|
+
on roles(fetch(:puma_role)) do |role|
|
9
|
+
|
10
|
+
upload_compiled_template = lambda do |template_name, unit_filename|
|
11
|
+
git_plugin.template_puma template_name, "#{fetch(:tmp_dir)}/#{unit_filename}", role
|
12
|
+
systemd_path = fetch(:puma_systemd_conf_dir, git_plugin.fetch_systemd_unit_path)
|
13
|
+
if fetch(:puma_systemctl_user) == :system
|
14
|
+
sudo "mv #{fetch(:tmp_dir)}/#{unit_filename} #{systemd_path}"
|
15
|
+
else
|
16
|
+
execute :mkdir, "-p", systemd_path
|
17
|
+
execute :mv, "#{fetch(:tmp_dir)}/#{unit_filename}", "#{systemd_path}"
|
20
18
|
end
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
if fetch(:puma_enable_socket_service)
|
25
|
-
upload_compiled_template.call("puma.socket", "#{fetch(:puma_service_unit_name)}.socket")
|
26
|
-
end
|
21
|
+
upload_compiled_template.call("puma.service", "#{fetch(:puma_service_unit_name)}.service")
|
27
22
|
|
28
|
-
|
29
|
-
|
23
|
+
if fetch(:puma_enable_socket_service)
|
24
|
+
upload_compiled_template.call("puma.socket", "#{fetch(:puma_service_unit_name)}.socket")
|
30
25
|
end
|
31
|
-
end
|
32
26
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
run_locally do
|
37
|
-
File.write('puma.service', git_plugin.compiled_template_puma("puma.service", fake_role.new("example.com")).string)
|
38
|
-
if fetch(:puma_enable_socket_service)
|
39
|
-
File.write('puma.socket', git_plugin.compiled_template_puma("puma.socket", fake_role.new("example.com")).string)
|
40
|
-
end
|
41
|
-
end
|
27
|
+
# Reload systemd
|
28
|
+
git_plugin.execute_systemd("daemon-reload")
|
29
|
+
invoke "puma:enable"
|
42
30
|
end
|
31
|
+
end
|
43
32
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
33
|
+
desc 'Uninstall Puma systemd service'
|
34
|
+
task :uninstall do
|
35
|
+
invoke 'puma:disable'
|
36
|
+
on roles(fetch(:puma_role)) do |role|
|
37
|
+
systemd_path = fetch(:puma_systemd_conf_dir, git_plugin.fetch_systemd_unit_path)
|
38
|
+
if fetch(:puma_systemctl_user) == :system
|
39
|
+
sudo "rm -f #{systemd_path}/#{fetch(:puma_service_unit_name)}*"
|
40
|
+
else
|
41
|
+
execute :rm, "-f", "#{systemd_path}/#{fetch(:puma_service_unit_name)}*"
|
53
42
|
end
|
43
|
+
git_plugin.execute_systemd("daemon-reload")
|
54
44
|
end
|
55
45
|
|
56
|
-
|
57
|
-
task :disable do
|
58
|
-
on roles(fetch(:puma_role)) do
|
59
|
-
git_plugin.execute_systemd("disable", fetch(:puma_service_unit_name))
|
60
|
-
git_plugin.execute_systemd("disable", fetch(:puma_service_unit_name) + ".socket") if fetch(:puma_enable_socket_service)
|
61
|
-
end
|
62
|
-
end
|
46
|
+
end
|
63
47
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
48
|
+
desc 'Enable Puma systemd service'
|
49
|
+
task :enable do
|
50
|
+
on roles(fetch(:puma_role)) do
|
51
|
+
git_plugin.execute_systemd("enable", fetch(:puma_service_unit_name))
|
52
|
+
git_plugin.execute_systemd("enable", fetch(:puma_service_unit_name) + ".socket") if fetch(:puma_enable_socket_service)
|
53
|
+
|
54
|
+
if fetch(:puma_systemctl_user) != :system && fetch(:puma_enable_lingering)
|
55
|
+
execute :loginctl, "enable-linger", fetch(:puma_lingering_user)
|
68
56
|
end
|
69
57
|
end
|
58
|
+
end
|
70
59
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
60
|
+
desc 'Disable Puma systemd service'
|
61
|
+
task :disable do
|
62
|
+
on roles(fetch(:puma_role)) do
|
63
|
+
git_plugin.execute_systemd("disable", fetch(:puma_service_unit_name))
|
64
|
+
git_plugin.execute_systemd("disable", fetch(:puma_service_unit_name) + ".socket") if fetch(:puma_enable_socket_service)
|
76
65
|
end
|
77
66
|
end
|
78
67
|
|
@@ -90,6 +79,13 @@ namespace :puma do
|
|
90
79
|
end
|
91
80
|
end
|
92
81
|
|
82
|
+
desc 'Stop Puma socket via systemd'
|
83
|
+
task :stop_socket do
|
84
|
+
on roles(fetch(:puma_role)) do
|
85
|
+
git_plugin.execute_systemd("stop", fetch(:puma_service_unit_name) + ".socket")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
93
89
|
desc 'Restarts or reloads Puma service via systemd'
|
94
90
|
task :smart_restart do
|
95
91
|
if fetch(:puma_phased_restart)
|
@@ -106,16 +102,23 @@ namespace :puma do
|
|
106
102
|
end
|
107
103
|
end
|
108
104
|
|
105
|
+
desc 'Restart Puma socket via systemd'
|
106
|
+
task :restart_socket do
|
107
|
+
on roles(fetch(:puma_role)) do
|
108
|
+
git_plugin.execute_systemd("restart", fetch(:puma_service_unit_name) + ".socket")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
109
112
|
desc 'Reload Puma service via systemd'
|
110
113
|
task :reload do
|
111
114
|
on roles(fetch(:puma_role)) do
|
112
115
|
service_ok = if fetch(:puma_systemctl_user) == :system
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
116
|
+
execute("#{fetch(:puma_systemctl_bin)} status #{fetch(:puma_service_unit_name)} > /dev/null", raise_on_non_zero_exit: false)
|
117
|
+
else
|
118
|
+
execute("#{fetch(:puma_systemctl_bin)} --user status #{fetch(:puma_service_unit_name)} > /dev/null", raise_on_non_zero_exit: false)
|
119
|
+
end
|
117
120
|
cmd = 'reload'
|
118
|
-
|
121
|
+
unless service_ok
|
119
122
|
cmd = 'restart'
|
120
123
|
end
|
121
124
|
if fetch(:puma_systemctl_user) == :system
|
@@ -1,28 +1,40 @@
|
|
1
|
+
# This file tells systemd how to run Puma as a 24/7 long-running daemon.
|
2
|
+
#
|
3
|
+
# Customize this file based on your bundler location, app directory, etc.
|
4
|
+
# Customize and copy this into /usr/lib/systemd/system (CentOS) or /lib/systemd/system (Ubuntu).
|
5
|
+
# Then run:
|
6
|
+
# - systemctl enable <%= fetch(:puma_service_unit_name) %>
|
7
|
+
# - systemctl {start,stop,restart} <%= fetch(:puma_service_unit_name) %>
|
8
|
+
#
|
9
|
+
#
|
10
|
+
# Use `journalctl -u <%= fetch(:puma_service_unit_name) %> -rn 100` to view the last 100 lines of log output.
|
11
|
+
#
|
1
12
|
[Unit]
|
2
13
|
Description=Puma HTTP Server for <%= "#{fetch(:application)} (#{fetch(:stage)})" %>
|
3
|
-
After=network.target
|
4
14
|
<%= "Requires=#{fetch(:puma_service_unit_name)}.socket" if fetch(:puma_enable_socket_service) %>
|
15
|
+
After=syslog.target network.target
|
5
16
|
|
6
17
|
[Service]
|
7
|
-
Type
|
18
|
+
Type=<%= service_unit_type %>
|
19
|
+
WatchdogSec=10
|
8
20
|
<%="User=#{puma_user(@role)}" if fetch(:puma_systemctl_user) == :system %>
|
9
21
|
WorkingDirectory=<%= current_path %>
|
10
|
-
|
11
|
-
# See https://github.com/rubygems/rubygems/issues/3254
|
12
|
-
ExecStart=<%= expanded_bundle_command %> exec --keep-file-descriptors puma -C <%= fetch(:puma_conf) %>
|
22
|
+
ExecStart=<%= expanded_bundle_command %> exec puma -e <%= fetch(:puma_env) %>
|
13
23
|
ExecReload=/bin/kill -USR1 $MAINPID
|
14
|
-
|
15
|
-
|
16
|
-
|
24
|
+
<%- Array(fetch(:puma_service_unit_env_files)).each do |file| %>
|
25
|
+
<%="EnvironmentFile=#{file}" -%>
|
26
|
+
<% end -%>
|
27
|
+
<% Array(fetch(:puma_service_unit_env_vars)).each do |environment_variable| %>
|
28
|
+
<%="Environment=\"#{environment_variable}\"" -%>
|
29
|
+
<% end -%>
|
17
30
|
|
18
|
-
|
19
|
-
<%="Environment=#{environment_variable}" %>
|
20
|
-
<% end %>
|
21
|
-
|
22
|
-
Restart=always
|
31
|
+
# if we crash, restart
|
23
32
|
RestartSec=1
|
33
|
+
Restart=on-failure
|
24
34
|
|
25
|
-
|
35
|
+
<%="StandardOutput=append:#{fetch(:puma_access_log)}" if fetch(:puma_access_log) %>
|
36
|
+
<%="StandardError=append:#{fetch(:puma_error_log)}" if fetch(:puma_error_log) %>
|
26
37
|
|
38
|
+
SyslogIdentifier=<%= fetch(:puma_service_unit_name) %>
|
27
39
|
[Install]
|
28
40
|
WantedBy=<%=(fetch(:puma_systemctl_user) == :system) ? "multi-user.target" : "default.target"%>
|
@@ -9,7 +9,6 @@ module Capistrano
|
|
9
9
|
:banner => "path to templates"
|
10
10
|
|
11
11
|
def copy_template
|
12
|
-
copy_file "../../../../capistrano/templates/puma.rb.erb", "#{templates_path}/puma.rb.erb"
|
13
12
|
copy_file "../../../../capistrano/templates/nginx_conf.erb", "#{templates_path}/nginx_conf.erb"
|
14
13
|
# copy_file "puma.rb.erb", "#{templates_path}/puma.rb.erb"
|
15
14
|
# copy_file "puma_init.erb", "#{templates_path}/puma_init.erb"
|