mina-puma-systemd 1.0.3 → 1.1.0
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/.rspec +3 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +26 -0
- data/README.md +7 -0
- data/Rakefile +5 -0
- data/lib/mina/puma_systemd/tasks.rake +37 -0
- data/lib/mina/puma_systemd/version.rb +1 -1
- data/mina-puma-systemd.gemspec +1 -0
- data/spec/puma_user_validation_spec.rb +145 -0
- data/spec/spec_helper.rb +25 -0
- metadata +24 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12a463a3e75e145ffa4fabeb12606fb31a33216848eab2538687acda5c464f36
|
4
|
+
data.tar.gz: c8fa964a4d042c4bf7f46bb686822f4fbc708314700184359c9c5cbb609dc547
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 792f8b5967c6eabeaa72ff626a577d45d88a0d7714c5c75b800ac63675fc3564aee4bc0ee2cbd1c22c3b342ae274732b2d7e42c9fae7ed95ad5b56dca84fb311
|
7
|
+
data.tar.gz: 9b7f628e238b4f04ee4a79175cadab455b917117274da759d34704180a2815be92d772561e7e4af52191d8e5d46e846ada1765bd649d9cd287fff7dab693f039
|
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.5
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## [1.1.0] - 2025-01-19
|
4
|
+
|
5
|
+
### Added
|
6
|
+
- User validation to prevent generation of invalid systemd files
|
7
|
+
- Validates that `puma_user` and `puma_group` are set before generating configs
|
8
|
+
- Provides clear error messages with examples when validation fails
|
9
|
+
- Applied to `puma:setup`, `puma:print`, and `puma:print_service` tasks
|
10
|
+
- Comprehensive test suite with RSpec
|
11
|
+
- 8 tests covering all validation scenarios
|
12
|
+
- Tests confirm invalid files would be generated without proper user config
|
13
|
+
- RSpec as development dependency
|
14
|
+
|
15
|
+
### Changed
|
16
|
+
- Updated README to highlight that `user` setting is required
|
17
|
+
- Added warning section about user configuration importance
|
18
|
+
|
19
|
+
### Fixed
|
20
|
+
- Prevents creation of systemd files with empty `User=` and `Group=` directives
|
21
|
+
- Users now get immediate, helpful error messages instead of cryptic systemd failures
|
22
|
+
|
23
|
+
## [1.0.3] - Previous releases
|
24
|
+
- Initial gem functionality
|
25
|
+
- Puma systemd service management
|
26
|
+
- Configuration templates
|
data/README.md
CHANGED
@@ -35,6 +35,7 @@ Make sure the following settings are set in your `config/deploy.rb`:
|
|
35
35
|
|
36
36
|
* `deploy_to` - deployment path
|
37
37
|
* `rails_env` - rails environement (will default to `production`)
|
38
|
+
* `user` - **REQUIRED** - deployment user (used for systemd service). Can be overridden with `puma_user`
|
38
39
|
|
39
40
|
Make sure the following directories exists on your server (they are added automatically to `shared_dirs`:
|
40
41
|
|
@@ -45,6 +46,12 @@ You can tweak some settings:
|
|
45
46
|
|
46
47
|
* `puma_systemctl` - systemctl command, default is ` sudo systemctl`. Other option would be `systemctl --user` if you have setup pumas as user service.
|
47
48
|
* `puma_service_name` - puma service name , default is `puma_#{fetch(:application_name)}_#{fetch(:puma_env)}`
|
49
|
+
* `puma_user` - user for running the service, defaults to `user` setting
|
50
|
+
* `puma_group` - group for running the service, defaults to `user` setting
|
51
|
+
|
52
|
+
## Important: User Configuration
|
53
|
+
|
54
|
+
**⚠️ The `user` setting is required!** The gem will validate that either `user` or `puma_user` is set before generating systemd files. Without a valid user, the systemd service will fail to start with cryptic error messages.
|
48
55
|
|
49
56
|
## Setting up server
|
50
57
|
|
data/Rakefile
CHANGED
@@ -94,6 +94,7 @@ namespace :puma do
|
|
94
94
|
|
95
95
|
desc 'Print nginx config in local terminal'
|
96
96
|
task :print do
|
97
|
+
validate_puma_user!
|
97
98
|
puts "---- puma.service ----------"
|
98
99
|
puts processed_puma_service_template
|
99
100
|
puts "---- puma.rb ---------------"
|
@@ -102,6 +103,7 @@ namespace :puma do
|
|
102
103
|
|
103
104
|
desc 'Print puma service config in local terminal'
|
104
105
|
task :print_service do
|
106
|
+
validate_puma_user!
|
105
107
|
puts processed_puma_service_template
|
106
108
|
end
|
107
109
|
|
@@ -112,6 +114,8 @@ namespace :puma do
|
|
112
114
|
|
113
115
|
desc 'Setup puma service on server'
|
114
116
|
task :setup do
|
117
|
+
validate_puma_user!
|
118
|
+
|
115
119
|
puma_service_config = fetch(:puma_service_config)
|
116
120
|
puma_config = fetch(:puma_config)
|
117
121
|
|
@@ -168,4 +172,37 @@ namespace :puma do
|
|
168
172
|
processed_puma_config_template.gsub("\n","\\n").gsub("'","\\'")
|
169
173
|
end
|
170
174
|
|
175
|
+
def validate_puma_user!
|
176
|
+
puma_user = fetch(:puma_user)
|
177
|
+
puma_group = fetch(:puma_group)
|
178
|
+
|
179
|
+
if puma_user.nil? || puma_user.to_s.strip.empty?
|
180
|
+
error! %(
|
181
|
+
ERROR: puma_user is not set!
|
182
|
+
|
183
|
+
The systemd service requires a user to run under.
|
184
|
+
Please set either :user or :puma_user in your deploy.rb:
|
185
|
+
|
186
|
+
Example:
|
187
|
+
set :user, 'deploy'
|
188
|
+
# or
|
189
|
+
set :puma_user, 'deploy'
|
190
|
+
)
|
191
|
+
end
|
192
|
+
|
193
|
+
if puma_group.nil? || puma_group.to_s.strip.empty?
|
194
|
+
error! %(
|
195
|
+
ERROR: puma_group is not set!
|
196
|
+
|
197
|
+
The systemd service requires a group to run under.
|
198
|
+
Please set either :user or :puma_group in your deploy.rb:
|
199
|
+
|
200
|
+
Example:
|
201
|
+
set :user, 'deploy'
|
202
|
+
# or
|
203
|
+
set :puma_group, 'deploy'
|
204
|
+
)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
171
208
|
end
|
data/mina-puma-systemd.gemspec
CHANGED
@@ -0,0 +1,145 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'puma user validation' do
|
4
|
+
# Mock the Mina DSL methods
|
5
|
+
def fetch(key, default = nil)
|
6
|
+
case key
|
7
|
+
when :user then @user
|
8
|
+
when :puma_user then @puma_user || fetch(:user)
|
9
|
+
when :puma_group then @puma_group || fetch(:user)
|
10
|
+
else
|
11
|
+
default
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def error!(message)
|
16
|
+
raise StandardError, message
|
17
|
+
end
|
18
|
+
|
19
|
+
# Include the validation method
|
20
|
+
def validate_puma_user!
|
21
|
+
puma_user = fetch(:puma_user)
|
22
|
+
puma_group = fetch(:puma_group)
|
23
|
+
|
24
|
+
if puma_user.nil? || puma_user.to_s.strip.empty?
|
25
|
+
error! %(
|
26
|
+
ERROR: puma_user is not set!
|
27
|
+
|
28
|
+
The systemd service requires a user to run under.
|
29
|
+
Please set either :user or :puma_user in your deploy.rb:
|
30
|
+
|
31
|
+
Example:
|
32
|
+
set :user, 'deploy'
|
33
|
+
# or
|
34
|
+
set :puma_user, 'deploy'
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
if puma_group.nil? || puma_group.to_s.strip.empty?
|
39
|
+
error! %(
|
40
|
+
ERROR: puma_group is not set!
|
41
|
+
|
42
|
+
The systemd service requires a group to run under.
|
43
|
+
Please set either :user or :puma_group in your deploy.rb:
|
44
|
+
|
45
|
+
Example:
|
46
|
+
set :user, 'deploy'
|
47
|
+
# or
|
48
|
+
set :puma_group, 'deploy'
|
49
|
+
)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe 'validate_puma_user!' do
|
54
|
+
context 'when user is not set' do
|
55
|
+
before do
|
56
|
+
@user = nil
|
57
|
+
@puma_user = nil
|
58
|
+
@puma_group = nil
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'raises an error about missing puma_user' do
|
62
|
+
expect { validate_puma_user! }.to raise_error(StandardError, /ERROR: puma_user is not set!/)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when user is set' do
|
67
|
+
before do
|
68
|
+
@user = 'deploy'
|
69
|
+
@puma_user = nil
|
70
|
+
@puma_group = nil
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'does not raise an error' do
|
74
|
+
expect { validate_puma_user! }.not_to raise_error
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'when puma_user is set but empty' do
|
79
|
+
before do
|
80
|
+
@user = nil
|
81
|
+
@puma_user = ''
|
82
|
+
@puma_group = 'deploy'
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'raises an error about missing puma_user' do
|
86
|
+
expect { validate_puma_user! }.to raise_error(StandardError, /ERROR: puma_user is not set!/)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'when puma_user is set but puma_group is empty' do
|
91
|
+
before do
|
92
|
+
@user = nil
|
93
|
+
@puma_user = 'deploy'
|
94
|
+
@puma_group = ''
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'raises an error about missing puma_group' do
|
98
|
+
expect { validate_puma_user! }.to raise_error(StandardError, /ERROR: puma_group is not set!/)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'when puma_user is set to whitespace' do
|
103
|
+
before do
|
104
|
+
@user = nil
|
105
|
+
@puma_user = ' '
|
106
|
+
@puma_group = 'deploy'
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'raises an error about missing puma_user' do
|
110
|
+
expect { validate_puma_user! }.to raise_error(StandardError, /ERROR: puma_user is not set!/)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context 'when both puma_user and puma_group are set' do
|
115
|
+
before do
|
116
|
+
@user = nil
|
117
|
+
@puma_user = 'deploy'
|
118
|
+
@puma_group = 'deploy'
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'does not raise an error' do
|
122
|
+
expect { validate_puma_user! }.not_to raise_error
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe 'systemd template generation' do
|
128
|
+
# Test to ensure the template would fail without proper user
|
129
|
+
it 'generates invalid systemd file when user is nil' do
|
130
|
+
@user = nil
|
131
|
+
@puma_user = nil
|
132
|
+
|
133
|
+
user_line = "User=#{fetch(:puma_user)}"
|
134
|
+
expect(user_line).to eq("User=") # This would be invalid
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'generates valid systemd file when user is set' do
|
138
|
+
@user = 'deploy'
|
139
|
+
@puma_user = nil
|
140
|
+
|
141
|
+
user_line = "User=#{fetch(:puma_user)}"
|
142
|
+
expect(user_line).to eq("User=deploy")
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'mina'
|
3
|
+
require 'mina/puma_systemd'
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.expect_with :rspec do |expectations|
|
7
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
8
|
+
end
|
9
|
+
|
10
|
+
config.mock_with :rspec do |mocks|
|
11
|
+
mocks.verify_partial_doubles = true
|
12
|
+
end
|
13
|
+
|
14
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
15
|
+
config.filter_run_when_matching :focus
|
16
|
+
config.disable_monkey_patching!
|
17
|
+
config.warnings = true
|
18
|
+
|
19
|
+
if config.files_to_run.one?
|
20
|
+
config.default_formatter = 'doc'
|
21
|
+
end
|
22
|
+
|
23
|
+
config.order = :random
|
24
|
+
Kernel.srand config.seed
|
25
|
+
end
|
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.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Elchinov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mina
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
69
83
|
description: Puma tasks for Mina and systemd
|
70
84
|
email:
|
71
85
|
- elik@elik.ru
|
@@ -74,6 +88,9 @@ extensions: []
|
|
74
88
|
extra_rdoc_files: []
|
75
89
|
files:
|
76
90
|
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".ruby-version"
|
93
|
+
- CHANGELOG.md
|
77
94
|
- Gemfile
|
78
95
|
- LICENSE.txt
|
79
96
|
- README.md
|
@@ -84,6 +101,8 @@ files:
|
|
84
101
|
- lib/mina/templates/puma.rb.template
|
85
102
|
- lib/mina/templates/puma.service.template
|
86
103
|
- mina-puma-systemd.gemspec
|
104
|
+
- spec/puma_user_validation_spec.rb
|
105
|
+
- spec/spec_helper.rb
|
87
106
|
homepage: https://github.com/railsblueprint/mina-puma-systemd
|
88
107
|
licenses:
|
89
108
|
- MIT
|
@@ -107,4 +126,6 @@ rubygems_version: 3.0.3
|
|
107
126
|
signing_key:
|
108
127
|
specification_version: 4
|
109
128
|
summary: Puma tasks for Mina and systemd
|
110
|
-
test_files:
|
129
|
+
test_files:
|
130
|
+
- spec/puma_user_validation_spec.rb
|
131
|
+
- spec/spec_helper.rb
|