mina-puma-systemd 1.0.1 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -6
- data/lib/mina/puma_systemd/tasks.rake +109 -1
- data/lib/mina/puma_systemd/version.rb +1 -1
- data/lib/mina/templates/puma.rb.template +43 -0
- data/lib/mina/templates/puma.service.template +34 -0
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33a95e8073143226568ca8a170d0c112ac5934e3e266a1af0f7e75aec839304c
|
4
|
+
data.tar.gz: 63ceb5ff64925777ae0454fedacb9b675cdc4e717154855d49ccc561f80fdef1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 620b23d2544bd4f5f89db7ac689e4b23440af4be90f7d986d5d657407e6c6919d4b9827dfcdb3e29bfd63a21093b2a636e05a737b7f32e8299c961fad70a24b4
|
7
|
+
data.tar.gz: d7edcc787a9c5e876adf53f81a2e01dfa366f6d6cff8d132d16d5d79da2eae6737e7ba3fc9a5d567a6a5e10d0e003649c1aa700f450fd2a46b5ca2224855b49b
|
data/README.md
CHANGED
@@ -10,6 +10,8 @@ This gem provides several mina tasks:
|
|
10
10
|
mina puma:start # Start puma
|
11
11
|
mina puma:stop # Stop puma
|
12
12
|
mina puma:status # Get status
|
13
|
+
mina puma:enable # Enables systemd service
|
14
|
+
mina puma:disable # Disables systemd service
|
13
15
|
|
14
16
|
## Installation
|
15
17
|
|
@@ -22,7 +24,6 @@ And then execute:
|
|
22
24
|
$ bundle
|
23
25
|
|
24
26
|
Note: by just including this gem, does not mean your development server will be Puma, for that, you need explicitly add `gem 'puma'` to your Gemfile and configure it.
|
25
|
-
This gem does not (yet) create puma and systemd service config files, you have to do it manually.
|
26
27
|
|
27
28
|
## Usage
|
28
29
|
|
@@ -45,6 +46,16 @@ You can tweak some settings:
|
|
45
46
|
* `puma_systemctl` - systemctl command, default is ` sudo systemctl`. Other option would be `systemctl --user` if you have setup pumas as user service.
|
46
47
|
* `puma_service_name` - puma service name , default is `puma_#{fetch(:application_name)}_#{fetch(:puma_env)}`
|
47
48
|
|
49
|
+
## Setting up server
|
50
|
+
|
51
|
+
mina puma:install # copies templates for puma config and systemd service to config/deploy/templates
|
52
|
+
mina puma:print # prints generated config files to stdout
|
53
|
+
mina puma:print_service # prints generated systemd service to stdout
|
54
|
+
mina puma:print_config # prints generated puma.rb to stdout
|
55
|
+
mina puma:setup # install config files on service in enables systemd service
|
56
|
+
|
57
|
+
Later commmand relies on sudo to work. If you don't want to grant sudo, print config files to console and install em manually.
|
58
|
+
|
48
59
|
|
49
60
|
Then:
|
50
61
|
|
@@ -54,7 +65,7 @@ $ mina puma:start
|
|
54
65
|
|
55
66
|
## Example
|
56
67
|
```ruby
|
57
|
-
require 'mina/
|
68
|
+
require 'mina/puma_systemd'
|
58
69
|
|
59
70
|
task :deploy do
|
60
71
|
deploy do
|
@@ -80,10 +91,6 @@ deploy ALL=(ALL) NOPASSWD: SERVICES
|
|
80
91
|
|
81
92
|
If you are paranoid, substitute `*` with exact service name. Better option would be to run as user service, but it did not work for me out of box on AWS AMI2.
|
82
93
|
|
83
|
-
## TODO
|
84
|
-
* Generate and upload puma.rb file
|
85
|
-
* Generate and upload puma systemd service
|
86
|
-
|
87
94
|
## Contributing
|
88
95
|
|
89
96
|
1. Fork it
|
@@ -4,12 +4,25 @@ require 'mina/rails'
|
|
4
4
|
namespace :puma do
|
5
5
|
set :shared_dirs, fetch(:shared_dirs, []).push("tmp/sockets", "tmp/pids")
|
6
6
|
|
7
|
-
set :
|
7
|
+
set :puma_user, -> { fetch(:user) }
|
8
|
+
set :puma_group, -> { fetch(:user) }
|
8
9
|
set :puma_env, -> { fetch(:rails_env, 'production') }
|
9
10
|
set :puma_root_path, -> { fetch(:current_path) }
|
10
11
|
|
12
|
+
set :puma_bundle_exec, -> { "/home/#{fetch(:puma_user)}/.rbenv/bin/rbenv exec bundle exec" }
|
13
|
+
set :systemd_root, -> { "/etc/systemd/system" }
|
14
|
+
|
11
15
|
set :puma_systemctl, -> { fetch(:systemctl, "sudo systemctl")}
|
12
16
|
set :puma_service_name, -> { "puma_#{fetch(:application_name)}_#{fetch(:puma_env)}" }
|
17
|
+
set :puma_service_config, -> { "#{fetch(:systemd_root)}/#{fetch(:puma_service_name)}.service" }
|
18
|
+
set :puma_config, -> { "#{fetch(:shared_path)}/puma.rb" }
|
19
|
+
|
20
|
+
set :puma_workers, 0
|
21
|
+
set :puma_threads, "1,5"
|
22
|
+
|
23
|
+
set :puma_restart_command, "bundle exec puma"
|
24
|
+
set :puma_preload_app, false
|
25
|
+
set :puma_init_active_record, true
|
13
26
|
|
14
27
|
desc 'Enable puma'
|
15
28
|
task enable: :remote_environment do
|
@@ -60,4 +73,99 @@ namespace :puma do
|
|
60
73
|
command "#{fetch(:puma_systemctl)} status -l #{fetch(:puma_service_name)}"
|
61
74
|
end
|
62
75
|
|
76
|
+
|
77
|
+
desc 'Install Puma config template to repo'
|
78
|
+
task :install do
|
79
|
+
run :local do
|
80
|
+
if File.exist? path_for_service_template
|
81
|
+
error! %(file exists; please rm to continue: #{path_for_service_template})
|
82
|
+
else
|
83
|
+
command %(mkdir -p config/deploy/templates)
|
84
|
+
command %(cp #{path_for_service_template(installed: false)} #{path_for_service_template})
|
85
|
+
end
|
86
|
+
if File.exist? path_for_config_template
|
87
|
+
error! %(file exists; please rm to continue: #{path_for_config_template})
|
88
|
+
else
|
89
|
+
command %(mkdir -p config/deploy/templates)
|
90
|
+
command %(cp #{path_for_config_template(installed: false)} #{path_for_config_template})
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
desc 'Print nginx config in local terminal'
|
96
|
+
task :print do
|
97
|
+
puts "---- puma.service ----------"
|
98
|
+
puts processed_puma_service_template
|
99
|
+
puts "---- puma.rb ---------------"
|
100
|
+
puts processed_puma_config_template
|
101
|
+
end
|
102
|
+
|
103
|
+
desc 'Print puma service config in local terminal'
|
104
|
+
task :print_service do
|
105
|
+
puts processed_puma_service_template
|
106
|
+
end
|
107
|
+
|
108
|
+
desc 'Print puma config in local terminal'
|
109
|
+
task :print_config do
|
110
|
+
puts processed_puma_config_template
|
111
|
+
end
|
112
|
+
|
113
|
+
desc 'Setup puma service on server'
|
114
|
+
task :setup do
|
115
|
+
puma_service_config = fetch(:puma_service_config)
|
116
|
+
puma_config = fetch(:puma_config)
|
117
|
+
|
118
|
+
comment %(Installing puma service config file to #{puma_service_config})
|
119
|
+
command %(echo -ne '#{escaped_puma_service_template}' | sudo tee #{puma_service_config} > /dev/null)
|
120
|
+
|
121
|
+
comment %(Installing puma.rb config file to #{puma_config})
|
122
|
+
command %(echo -ne '#{escaped_puma_config_template}' > #{puma_config})
|
123
|
+
|
124
|
+
invoke :'puma:enable'
|
125
|
+
end
|
126
|
+
|
127
|
+
def path_for_service_template installed: true
|
128
|
+
installed ?
|
129
|
+
File.expand_path('./config/deploy/templates/puma.service.template') :
|
130
|
+
File.expand_path('../../templates/puma.service.template', __FILE__)
|
131
|
+
end
|
132
|
+
|
133
|
+
def path_for_config_template installed: true
|
134
|
+
installed ?
|
135
|
+
File.expand_path('./config/deploy/templates/puma.rb.template') :
|
136
|
+
File.expand_path('../../templates/puma.rb.template', __FILE__)
|
137
|
+
end
|
138
|
+
|
139
|
+
def puma_service_template
|
140
|
+
installed_path = path_for_service_template
|
141
|
+
template_path = path_for_service_template installed: false
|
142
|
+
|
143
|
+
File.exist?(installed_path) ? installed_path : template_path
|
144
|
+
end
|
145
|
+
|
146
|
+
def processed_puma_service_template
|
147
|
+
erb = File.read(puma_service_template)
|
148
|
+
ERB.new(erb, trim_mode: '-').result(binding)
|
149
|
+
end
|
150
|
+
|
151
|
+
def escaped_puma_service_template
|
152
|
+
processed_puma_service_template.gsub("\n","\\n").gsub("'","\\'")
|
153
|
+
end
|
154
|
+
|
155
|
+
def puma_config_template
|
156
|
+
installed_path = path_for_config_template
|
157
|
+
template_path = path_for_config_template installed: false
|
158
|
+
|
159
|
+
File.exist?(installed_path) ? installed_path : template_path
|
160
|
+
end
|
161
|
+
|
162
|
+
def processed_puma_config_template
|
163
|
+
erb = File.read(puma_config_template)
|
164
|
+
ERB.new(erb, trim_mode: '-').result(binding)
|
165
|
+
end
|
166
|
+
|
167
|
+
def escaped_puma_config_template
|
168
|
+
processed_puma_config_template.gsub("\n","\\n").gsub("'","\\'")
|
169
|
+
end
|
170
|
+
|
63
171
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env puma
|
2
|
+
|
3
|
+
environment "<%= fetch(:puma_env) %>"
|
4
|
+
|
5
|
+
app_dir = "<%= fetch(:current_path) %>"
|
6
|
+
|
7
|
+
directory app_dir
|
8
|
+
rackup "#{app_dir}/config.ru"
|
9
|
+
pidfile "#{app_dir}/tmp/pids/puma.pid"
|
10
|
+
state_path "#{app_dir}/tmp/pids/puma.state"
|
11
|
+
stdout_redirect "#{app_dir}/log/puma_access.log", "#{app_dir}/log/puma_error.log", true
|
12
|
+
bind "unix://#{app_dir}/tmp/sockets/puma.sock"
|
13
|
+
<% if fetch(:puma_tag) %>
|
14
|
+
tag "<%= fetch(:puma_tag)%>"
|
15
|
+
<% end %>
|
16
|
+
|
17
|
+
threads <%= fetch(:puma_threads) %>
|
18
|
+
workers <%= fetch(:puma_workers) %>
|
19
|
+
|
20
|
+
restart_command "<%= fetch(:puma_restart_command) %>"
|
21
|
+
|
22
|
+
<% if fetch(:puma_preload_app) %>
|
23
|
+
preload_app!
|
24
|
+
<% else %>
|
25
|
+
prune_bundler
|
26
|
+
<% end %>
|
27
|
+
|
28
|
+
on_restart do
|
29
|
+
puts "Refreshing Gemfile"
|
30
|
+
ENV["BUNDLE_GEMFILE"] = "<%= fetch(:bundle_gemfile, "#{fetch(:current_path)}/Gemfile") %>"
|
31
|
+
end
|
32
|
+
|
33
|
+
<% if fetch(:puma_preload_app) && fetch(:puma_init_active_record) %>
|
34
|
+
before_fork do
|
35
|
+
ActiveRecord::Base.connection_pool.disconnect!
|
36
|
+
end
|
37
|
+
|
38
|
+
on_worker_boot do
|
39
|
+
ActiveSupport.on_load(:active_record) do
|
40
|
+
ActiveRecord::Base.establish_connection
|
41
|
+
end
|
42
|
+
end
|
43
|
+
<% end %>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
[Unit]
|
2
|
+
Description=Puma HTTP Server for <%= "#{fetch(:application)} (#{fetch(:stage)})" %>
|
3
|
+
After=network.target
|
4
|
+
<%= "Requires=#{fetch(:puma_service_name)}.socket" if fetch(:puma_enable_socket_service) %>
|
5
|
+
|
6
|
+
[Service]
|
7
|
+
Type=notify
|
8
|
+
WatchdogSec=10
|
9
|
+
|
10
|
+
User=<%= fetch(:puma_user) %>
|
11
|
+
Group=<%= fetch(:puma_group) %>
|
12
|
+
WorkingDirectory=<%= fetch(:current_path) %>
|
13
|
+
|
14
|
+
ExecStart=<%= fetch(:puma_bundle_exec) %> puma -C <%= fetch(:shared_path) %>/puma.rb config.ru
|
15
|
+
ExecStop=<%= fetch(:puma_bundle_exec) %> pumactl -S <%= fetch(:shared_path) %>/pids/puma.state stop
|
16
|
+
ExecReload=<%= fetch(:puma_bundle_exec) %> pumactl -F <%= fetch(:shared_path) %>/puma.rb phased-restart
|
17
|
+
|
18
|
+
PIDFile=<%= fetch(:shared_path) %>/tmp/pids/puma.pid
|
19
|
+
|
20
|
+
<%="EnvironmentFile=#{fetch(:puma_service_unit_env_file)}" if fetch(:puma_service_unit_env_file) %>
|
21
|
+
|
22
|
+
<% fetch(:puma_service_unit_env_vars, []).each do |environment_variable| %>
|
23
|
+
<%="Environment=#{environment_variable}" %>
|
24
|
+
<% end -%>
|
25
|
+
Environment=ALLOC_ARENA_MAX=2
|
26
|
+
|
27
|
+
|
28
|
+
Restart=always
|
29
|
+
RestartSec=1
|
30
|
+
|
31
|
+
SyslogIdentifier=puma_<%= "#{fetch(:application)}_#{fetch(:stage)}" %>
|
32
|
+
|
33
|
+
[Install]
|
34
|
+
WantedBy=multi-user.target
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mina-puma-systemd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Elchinov
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mina
|
@@ -81,12 +81,14 @@ files:
|
|
81
81
|
- lib/mina/puma_systemd.rb
|
82
82
|
- lib/mina/puma_systemd/tasks.rake
|
83
83
|
- lib/mina/puma_systemd/version.rb
|
84
|
+
- lib/mina/templates/puma.rb.template
|
85
|
+
- lib/mina/templates/puma.service.template
|
84
86
|
- mina-puma-systemd.gemspec
|
85
87
|
homepage: https://github.com/railsblueprint/mina-puma-systemd
|
86
88
|
licenses:
|
87
89
|
- MIT
|
88
90
|
metadata: {}
|
89
|
-
post_install_message:
|
91
|
+
post_install_message:
|
90
92
|
rdoc_options: []
|
91
93
|
require_paths:
|
92
94
|
- lib
|
@@ -102,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
104
|
version: '0'
|
103
105
|
requirements: []
|
104
106
|
rubygems_version: 3.0.3
|
105
|
-
signing_key:
|
107
|
+
signing_key:
|
106
108
|
specification_version: 4
|
107
109
|
summary: Puma tasks for Mina and systemd
|
108
110
|
test_files: []
|