mina-puma-systemd 1.0.1 → 1.0.2
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 +4 -4
- data/README.md +12 -5
- 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: cee49f9c394f0983df8630691473adf2ba83c7f63380457d327edb635d5f68bf
|
4
|
+
data.tar.gz: ee26eed2ddaf3f0ee8601c5ccf9072fee4ec4a116ea31ac3c6a3f32f35a361cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 536e4e40908b2ec4588bd22763e76c8e9495a60f728839eb65975bacf64eb66e0ee733d45d035faad65e8342dfd2542dcc57efaefc9210a418d5fbe50a268eb3
|
7
|
+
data.tar.gz: 7b9a8996aeece1afb2845439d3dea35dd1c5bc58813c976475b4154670962e848b28db3a011edc945c271a132454cd03816368c340db889669119ae3a2df127a
|
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
|
|
@@ -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.2
|
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: 2023-12-28 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: []
|