mina-ng-puma 1.2.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 +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +101 -0
- data/Rakefile +1 -0
- data/lib/mina/puma.rb +1 -0
- data/lib/mina/puma/tasks.rake +156 -0
- data/lib/mina/puma/version.rb +5 -0
- data/mina-ng-puma.gemspec +26 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d7ff92738b7a21a7e6a6cd66258201ef8c42e399ffd2bb2e59bca8d70a9a8b9e
|
4
|
+
data.tar.gz: c056becb525af7c2b690052e18695c743697b4195152be752b060d97422e4a44
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4716a49a617df7a5f525cc32581fc8c8666ff33b285895af3b633f2e28c333ceb8a7c3432cd79f2a8505a2b3fb5e849528d510d36779ff9115ec0d1d0f25235e
|
7
|
+
data.tar.gz: 062cf312f432336561393d685c00d2f9cef45fbc6923728de0f76126bda0df4a4ba6e6de4fab527cf1676f2bea47582a713d4d9326cf75524115f5dc86b015ae
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Tobias Sandelius
|
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,101 @@
|
|
1
|
+
# Next Generation Mina Puma
|
2
|
+
|
3
|
+
I refactor mina-puma( https://github.com/untitledkingdom/mina-puma ) because of the below:
|
4
|
+
|
5
|
+
1. `phased_restart` and `restart` need start puma correctly when puma is down.
|
6
|
+
2. `phased_restart` and `restart` should confirm puma restart successfully.
|
7
|
+
3. check `puma_pid` instead of `pumactl_socket`.
|
8
|
+
|
9
|
+
[Mina](https://github.com/nadarei/mina) tasks for handle with
|
10
|
+
[Puma](https://github.com/puma/puma).
|
11
|
+
|
12
|
+
This gem provides several mina tasks:
|
13
|
+
|
14
|
+
mina puma:phased_restart # Restart puma (using phased restart)
|
15
|
+
mina puma:hard_restart # Restart puma (using stop, then start)
|
16
|
+
mina puma:restart # Restart puma (using pumactl)
|
17
|
+
mina puma:start # Start puma
|
18
|
+
mina puma:stop # Stop puma
|
19
|
+
mina puma:status # Get status
|
20
|
+
|
21
|
+
## Installation
|
22
|
+
|
23
|
+
Add this line to your application's Gemfile:
|
24
|
+
|
25
|
+
gem 'mina-ng-puma', require: false
|
26
|
+
|
27
|
+
And then execute:
|
28
|
+
|
29
|
+
$ bundle
|
30
|
+
|
31
|
+
Or install it yourself as:
|
32
|
+
|
33
|
+
$ gem install mina-ng-puma
|
34
|
+
|
35
|
+
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.
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
Run:
|
40
|
+
```
|
41
|
+
mina init
|
42
|
+
```
|
43
|
+
to generate `config/deploy.rb` file if you have not configured it yet.
|
44
|
+
|
45
|
+
Add this to your `config/deploy.rb` file:
|
46
|
+
|
47
|
+
require 'mina/puma'
|
48
|
+
|
49
|
+
Make sure the following settings are set in your `config/deploy.rb`:
|
50
|
+
|
51
|
+
* `deploy_to` - deployment path
|
52
|
+
|
53
|
+
Make sure the following directories exists on your server:
|
54
|
+
|
55
|
+
* `shared/tmp/sockets` - directory for socket files.
|
56
|
+
* `shared/tmp/pids` - directory for pid files.
|
57
|
+
|
58
|
+
OR you can set other directories by setting follow variables:
|
59
|
+
|
60
|
+
* `puma_socket` - puma socket file, default is `shared/tmp/sockets/puma.sock`
|
61
|
+
* `puma_pid` - puma pid file, default `shared/tmp/pids/puma.pid`
|
62
|
+
* `puma_state` - puma state file, default `shared/tmp/sockets/puma.state`
|
63
|
+
* `puma_stdout` - puma redirect path for stdout, default `shared/log/puma.log`
|
64
|
+
* `puma_stderr` - puma redirect path for stderr, default `shared/log/puma.log`
|
65
|
+
* `pumactl_socket` - pumactl socket file, default `shared/tmp/sockets/pumactl.sock`
|
66
|
+
* `puma_root_path` - puma command execute root path, default `current`
|
67
|
+
|
68
|
+
Then:
|
69
|
+
|
70
|
+
```
|
71
|
+
$ bundle exec mina puma:start
|
72
|
+
```
|
73
|
+
|
74
|
+
## Example
|
75
|
+
```ruby
|
76
|
+
require 'mina/puma'
|
77
|
+
|
78
|
+
# Add pids and sockets directories to shared dirs
|
79
|
+
set :shared_dirs, fetch(:shared_dirs, []).push('log', 'tmp/pids', 'tmp/sockets')
|
80
|
+
|
81
|
+
task :deploy do
|
82
|
+
deploy do
|
83
|
+
invoke :'git:clone'
|
84
|
+
invoke :'deploy:link_shared_paths'
|
85
|
+
...
|
86
|
+
|
87
|
+
on :launch do
|
88
|
+
...
|
89
|
+
invoke :'puma:phased_restart'
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
```
|
94
|
+
|
95
|
+
## Contributing
|
96
|
+
|
97
|
+
1. Fork it
|
98
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
99
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
100
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
101
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/mina/puma.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path("../puma/tasks.rake", __FILE__)
|
@@ -0,0 +1,156 @@
|
|
1
|
+
require 'mina/bundler'
|
2
|
+
require 'mina/rails'
|
3
|
+
|
4
|
+
namespace :puma do
|
5
|
+
set :web_server, :puma
|
6
|
+
|
7
|
+
set :puma_role, -> { fetch(:user) }
|
8
|
+
set :puma_env, -> { fetch(:rails_env, 'production') }
|
9
|
+
set :puma_config, -> { "#{fetch(:shared_path)}/config/puma.rb" }
|
10
|
+
set :puma_socket, -> { "#{fetch(:shared_path)}/tmp/sockets/puma.sock" }
|
11
|
+
set :puma_state, -> { "#{fetch(:shared_path)}/tmp/sockets/puma.state" }
|
12
|
+
set :puma_pid, -> { "#{fetch(:shared_path)}/tmp/pids/puma.pid" }
|
13
|
+
set :puma_stdout, -> { "#{fetch(:shared_path)}/log/puma.log" }
|
14
|
+
set :puma_stderr, -> { "#{fetch(:shared_path)}/log/puma.log" }
|
15
|
+
set :puma_cmd, -> { "#{fetch(:bundle_prefix)} puma" }
|
16
|
+
set :pumactl_cmd, -> { "#{fetch(:bundle_prefix)} pumactl" }
|
17
|
+
set :pumactl_socket, -> { "#{fetch(:shared_path)}/tmp/sockets/pumactl.sock" }
|
18
|
+
set :puma_root_path, -> { fetch(:current_path) }
|
19
|
+
|
20
|
+
desc 'Start puma'
|
21
|
+
task :start do
|
22
|
+
puma_port_option = "-p #{fetch(:puma_port)}" if set?(:puma_port)
|
23
|
+
|
24
|
+
comment "Starting Puma..."
|
25
|
+
command %[
|
26
|
+
if [ -e "#{fetch(:puma_pid)}" ] && kill -0 "$(cat #{fetch(:puma_pid)})" 2> /dev/null; then
|
27
|
+
echo 'Puma is already running!';
|
28
|
+
else
|
29
|
+
if [ -e "#{fetch(:puma_config)}" ]; then
|
30
|
+
cd #{fetch(:puma_root_path)} && #{fetch(:puma_cmd)} -q -d -e #{fetch(:puma_env)} -C #{fetch(:puma_config)}
|
31
|
+
else
|
32
|
+
cd #{fetch(:puma_root_path)} && #{fetch(:puma_cmd)} -q -d -e #{fetch(:puma_env)} -b "unix://#{fetch(:puma_socket)}" #{puma_port_option} -S #{fetch(:puma_state)} --pidfile #{fetch(:puma_pid)} --control 'unix://#{fetch(:pumactl_socket)}' --redirect-stdout "#{fetch(:puma_stdout)}" --redirect-stderr "#{fetch(:puma_stderr)}"
|
33
|
+
fi
|
34
|
+
fi
|
35
|
+
]
|
36
|
+
end
|
37
|
+
|
38
|
+
desc 'Stop puma'
|
39
|
+
task :stop do
|
40
|
+
comment "Stopping Puma..."
|
41
|
+
pumactl_command 'stop'
|
42
|
+
command %[rm -f '#{fetch(:pumactl_socket)}']
|
43
|
+
end
|
44
|
+
|
45
|
+
desc 'Restart puma'
|
46
|
+
task :restart do
|
47
|
+
comment "Restart Puma...."
|
48
|
+
pumactl_restart_command 'restart'
|
49
|
+
end
|
50
|
+
|
51
|
+
desc 'Restart puma (phased restart)'
|
52
|
+
task :phased_restart do
|
53
|
+
comment "Restart Puma -- phased..."
|
54
|
+
pumactl_restart_command 'phased-restart'
|
55
|
+
end
|
56
|
+
|
57
|
+
desc 'Restart puma (hard restart)'
|
58
|
+
task :hard_restart do
|
59
|
+
comment "Restart Puma -- hard..."
|
60
|
+
invoke 'puma:stop'
|
61
|
+
wait_quit_or_force_quit_command
|
62
|
+
invoke 'puma:start'
|
63
|
+
end
|
64
|
+
|
65
|
+
desc 'Get status of puma'
|
66
|
+
task :status do
|
67
|
+
comment "Puma status..."
|
68
|
+
pumactl_command 'status'
|
69
|
+
end
|
70
|
+
|
71
|
+
def pumactl_command(command)
|
72
|
+
cmd = %{
|
73
|
+
if [ -e "#{fetch(:puma_pid)}" ]; then
|
74
|
+
if kill -0 "$(cat #{fetch(:puma_pid)})" 2> /dev/null; then
|
75
|
+
if [ -e "#{fetch(:puma_config)}" ]; then
|
76
|
+
cd #{fetch(:puma_root_path)} && #{fetch(:pumactl_cmd)} -F #{fetch(:puma_config)} #{command}
|
77
|
+
else
|
78
|
+
cd #{fetch(:puma_root_path)} && #{fetch(:pumactl_cmd)} -S #{fetch(:puma_state)} -C "unix://#{fetch(:pumactl_socket)}" --pidfile #{fetch(:puma_pid)} #{command}
|
79
|
+
fi
|
80
|
+
else
|
81
|
+
rm "#{fetch(:puma_pid)}"
|
82
|
+
fi
|
83
|
+
else
|
84
|
+
echo 'Puma is not running!';
|
85
|
+
fi
|
86
|
+
}
|
87
|
+
command cmd
|
88
|
+
end
|
89
|
+
|
90
|
+
def pumactl_restart_command(command)
|
91
|
+
puma_port_option = "-p #{fetch(:puma_port)}" if set?(:puma_port)
|
92
|
+
|
93
|
+
cmd = %{
|
94
|
+
if [ -e "#{fetch(:puma_pid)}" ] && kill -0 "$(cat #{fetch(:puma_pid)})" 2> /dev/null; then
|
95
|
+
if [ -e "#{fetch(:puma_config)}" ]; then
|
96
|
+
cd #{fetch(:puma_root_path)} && #{fetch(:pumactl_cmd)} -F #{fetch(:puma_config)} #{command}
|
97
|
+
else
|
98
|
+
cd #{fetch(:puma_root_path)} && #{fetch(:pumactl_cmd)} -S #{fetch(:puma_state)} -C "unix://#{fetch(:pumactl_socket)}" --pidfile #{fetch(:puma_pid)} #{command}
|
99
|
+
fi
|
100
|
+
else
|
101
|
+
echo "Puma is not running, restarting";
|
102
|
+
if [ -e "#{fetch(:puma_config)}" ]; then
|
103
|
+
cd #{fetch(:puma_root_path)} && #{fetch(:puma_cmd)} -q -d -e #{fetch(:puma_env)} -C #{fetch(:puma_config)}
|
104
|
+
else
|
105
|
+
cd #{fetch(:puma_root_path)} && #{fetch(:puma_cmd)} -q -d -e #{fetch(:puma_env)} -b "unix://#{fetch(:puma_socket)}" #{puma_port_option} -S #{fetch(:puma_state)} --pidfile #{fetch(:puma_pid)} --control 'unix://#{fetch(:pumactl_socket)}' --redirect-stdout "#{fetch(:puma_stdout)}" --redirect-stderr "#{fetch(:puma_stderr)}"
|
106
|
+
fi
|
107
|
+
fi
|
108
|
+
}
|
109
|
+
command cmd
|
110
|
+
end
|
111
|
+
|
112
|
+
def wait_quit_or_force_quit_command
|
113
|
+
cmd = %{
|
114
|
+
quit_flag=false
|
115
|
+
times=3
|
116
|
+
while [ $times -gt 0 ]; do
|
117
|
+
if [ -e "#{fetch(:puma_pid)}" ]; then
|
118
|
+
#echo ">>> sleep 1"
|
119
|
+
sleep 1
|
120
|
+
times=$[$times -1]
|
121
|
+
else
|
122
|
+
quit_flag=true
|
123
|
+
break
|
124
|
+
fi
|
125
|
+
done
|
126
|
+
|
127
|
+
if [ $quit_flag == false ]; then
|
128
|
+
echo "Friendly quit fail, force quit..."
|
129
|
+
|
130
|
+
#echo "kill -9 $(cat #{fetch(:puma_pid)})"
|
131
|
+
kill -9 $(cat "#{fetch(:puma_pid)}") 2> /dev/null
|
132
|
+
|
133
|
+
force_quit_flag=false
|
134
|
+
force_times=3
|
135
|
+
while [ $force_times -gt 0 ]; do
|
136
|
+
if [ -e "#{fetch(:puma_pid)}" ] && kill -0 $(cat "#{fetch(:puma_pid)}") 2> /dev/null; then
|
137
|
+
sleep 1
|
138
|
+
force_times=$[$force_times -1]
|
139
|
+
else
|
140
|
+
force_quit_flag=true
|
141
|
+
echo "Force quit successfully"
|
142
|
+
break
|
143
|
+
fi
|
144
|
+
done
|
145
|
+
|
146
|
+
if [ "$force_quit_flag" == false ]; then
|
147
|
+
echo "Force quit fail too, please check the script!!!"
|
148
|
+
exit 1
|
149
|
+
fi
|
150
|
+
else
|
151
|
+
echo "Friendly quit successfully"
|
152
|
+
fi
|
153
|
+
}
|
154
|
+
command cmd
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mina/puma/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'mina-ng-puma'
|
8
|
+
spec.version = Mina::Puma::VERSION
|
9
|
+
spec.authors = ['windy']
|
10
|
+
spec.email = ['lyfi2003@gmail.com']
|
11
|
+
spec.description = %q{Next Generation Puma tasks for Mina}
|
12
|
+
spec.summary = %q{Next Generation Puma tasks for Mina}
|
13
|
+
spec.homepage = 'https://github.com/windy/mina-ng-puma'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'mina', '~> 1.2.0'
|
22
|
+
spec.add_dependency 'puma', '>= 2.13'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '>= 1.3'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mina-ng-puma
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- windy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-02-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mina
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: puma
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.13'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Next Generation Puma tasks for Mina
|
70
|
+
email:
|
71
|
+
- lyfi2003@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/mina/puma.rb
|
82
|
+
- lib/mina/puma/tasks.rake
|
83
|
+
- lib/mina/puma/version.rb
|
84
|
+
- mina-ng-puma.gemspec
|
85
|
+
homepage: https://github.com/windy/mina-ng-puma
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubygems_version: 3.0.2
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Next Generation Puma tasks for Mina
|
108
|
+
test_files: []
|