puma-daemon 0.1.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +22 -8
- data/.gitignore +2 -0
- data/CHANGELOG.md +36 -0
- data/Dockerfile.download +1 -1
- data/{Gemfile → Gemfile.puma-v5} +2 -0
- data/Gemfile.puma-v6 +15 -0
- data/Makefile +23 -0
- data/README.adoc +144 -65
- data/README.pdf +9557 -1
- data/Rakefile +1 -1
- data/bin/console +1 -1
- data/codecov.yml +4 -0
- data/example/cluster.sh +61 -0
- data/example/config.ru +5 -0
- data/example/puma.rb +78 -0
- data/example/single.sh +64 -0
- data/exe/pumad +5 -0
- data/lib/puma/daemon/cli.rb +4 -2
- data/lib/puma/daemon/configuration.rb +4 -0
- data/lib/puma/daemon/runner_adapter.rb +49 -0
- data/lib/puma/daemon/version.rb +1 -1
- data/lib/puma/daemon.rb +4 -3
- data/puma-daemon.gemspec +5 -3
- metadata +30 -9
- data/lib/puma/daemon/runner.rb +0 -30
data/Rakefile
CHANGED
@@ -26,7 +26,7 @@ end
|
|
26
26
|
task build: :permissions
|
27
27
|
|
28
28
|
YARD::Rake::YardocTask.new(:doc) do |t|
|
29
|
-
t.files = %w[lib/**/*.rb exe
|
29
|
+
t.files = %w[lib/**/*.rb exe/* - README.adoc CHANGELOG.md LICENSE.txt]
|
30
30
|
t.options.unshift('--title', '"Puma Daemon"')
|
31
31
|
t.after = -> { exec('open doc/index.html') }
|
32
32
|
end
|
data/bin/console
CHANGED
@@ -7,7 +7,7 @@ require 'puma/daemon'
|
|
7
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
8
8
|
# with your gem easier. You can also use a different console, if you like.
|
9
9
|
|
10
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile.puma-v5!)
|
11
11
|
# require "pry"
|
12
12
|
# Pry.start
|
13
13
|
|
data/codecov.yml
ADDED
data/example/cluster.sh
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
export txtblk='\e[0;30m'
|
4
|
+
export txtred='\e[0;31m'
|
5
|
+
export txtgrn='\e[0;32m'
|
6
|
+
export txtylw='\e[0;33m'
|
7
|
+
export txtblu='\e[0;34m'
|
8
|
+
export txtpur='\e[0;35m'
|
9
|
+
export txtcyn='\e[0;36m'
|
10
|
+
export txtwht='\e[0;37m'
|
11
|
+
export clr='\e[0;0m'
|
12
|
+
|
13
|
+
[[ -f cluster.sh ]] || {
|
14
|
+
echo -e "${txtred}Please run this from the ./example folder.${clr}"
|
15
|
+
exit 1
|
16
|
+
}
|
17
|
+
|
18
|
+
[[ -f ../Gemfile ]] || {
|
19
|
+
echo -e "${txtred}Please choose either Puma v5 or Puma v6, by running:${clr}"
|
20
|
+
echo -e "${txtgrn}make puma-v5 or make puma-v6"
|
21
|
+
exit 2
|
22
|
+
}
|
23
|
+
|
24
|
+
echo -e "${txtblu}Ensuring your dependencies are installed...${clr}"
|
25
|
+
|
26
|
+
(
|
27
|
+
cd .. || exit 2;
|
28
|
+
bundle check || bundle install
|
29
|
+
) >/dev/null
|
30
|
+
|
31
|
+
pid=$(ps -ef | grep puma | grep example | awk '{print $2}')
|
32
|
+
|
33
|
+
[[ -n $pid ]] && kill $pid && sleep 1
|
34
|
+
|
35
|
+
echo -e "${txtblu}Starting Puma in cluster mode.${clr}"
|
36
|
+
|
37
|
+
command="bundle exec puma -I ../lib -C $(pwd)/puma.rb -w 4"
|
38
|
+
echo -e "${txtblu}Running Command:"
|
39
|
+
echo -e "${txtgrn}${command}${clr}"
|
40
|
+
eval "${command}"
|
41
|
+
|
42
|
+
echo -e "${txtblu}Verifying Puma is running...${clr}"
|
43
|
+
|
44
|
+
sleep 0.5
|
45
|
+
|
46
|
+
output=$(mktemp)
|
47
|
+
|
48
|
+
set -e
|
49
|
+
|
50
|
+
curl http://0.0.0.0:9292/ > "${output}" 2>/dev/null
|
51
|
+
|
52
|
+
[[ $(cat ${output}) == "Hello World" ]] || {
|
53
|
+
echo -e "${txtred}Invalid response:${clr}">&2
|
54
|
+
cat ${output}
|
55
|
+
exit 3
|
56
|
+
}
|
57
|
+
|
58
|
+
echo -e "${txtgrn}Puma Daemon is running and returning the expected string.${clr}"
|
59
|
+
|
60
|
+
ps -ef | grep [p]uma
|
61
|
+
|
data/example/config.ru
ADDED
data/example/puma.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'puma/daemon'
|
4
|
+
|
5
|
+
# The directory to operate out of.
|
6
|
+
# The default is the current directory.
|
7
|
+
|
8
|
+
# The default is “development”.
|
9
|
+
|
10
|
+
environment 'development'
|
11
|
+
|
12
|
+
# Store the pid of the server in the file at “path”.
|
13
|
+
|
14
|
+
pidfile '/tmp/puma.pid'
|
15
|
+
|
16
|
+
# Use “path” as the file to store the server info state. This is
|
17
|
+
# used by “pumactl” to query and control the server.
|
18
|
+
state_path '/tmp/puma.state'
|
19
|
+
|
20
|
+
# Redirect STDOUT and STDERR to files specified. The 3rd parameter
|
21
|
+
# (“append”) specifies whether the output is appended, the default is
|
22
|
+
# “false”.
|
23
|
+
stdout_redirect '/tmp/puma_access.log', '/tmp/puma_error.log', true
|
24
|
+
|
25
|
+
quiet
|
26
|
+
|
27
|
+
threads 0, 16
|
28
|
+
|
29
|
+
# Bind the server to “url”. “tcp://”, “unix://” and “ssl://” are the only
|
30
|
+
# accepted protocols.
|
31
|
+
# The default is “tcp://0.0.0.0:9292”.
|
32
|
+
|
33
|
+
bind 'unix:///tmp/puma.sock'
|
34
|
+
bind 'tcp://0.0.0.0:9292'
|
35
|
+
|
36
|
+
# Instead of “bind 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'” you
|
37
|
+
# can also use the “ssl_bind” option.
|
38
|
+
|
39
|
+
# ssl_bind '127.0.0.1', '9292', { key: path_to_key, cert: path_to_cert }
|
40
|
+
|
41
|
+
# Code to run before doing a restart. This code should
|
42
|
+
# close log files, database connections, etc.
|
43
|
+
|
44
|
+
# This can be called multiple times to add code each time.
|
45
|
+
|
46
|
+
on_restart do
|
47
|
+
puts 'On restart...'
|
48
|
+
end
|
49
|
+
|
50
|
+
# Command to use to restart puma. This should be just how to
|
51
|
+
# load puma itself (ie. 'ruby -Ilib bin/puma'), not the arguments
|
52
|
+
# to puma, as those are the same as the original process.
|
53
|
+
|
54
|
+
# === Cluster mode ===
|
55
|
+
|
56
|
+
# How many worker processes to run.
|
57
|
+
# The default is “0”.
|
58
|
+
|
59
|
+
workers 2
|
60
|
+
|
61
|
+
# Code to run when a worker boots to setup the process before booting
|
62
|
+
# the app.
|
63
|
+
# This can be called multiple times to add hooks.
|
64
|
+
|
65
|
+
# === Puma control rack application ===
|
66
|
+
|
67
|
+
# Start the puma control rack application on “url”. This application can
|
68
|
+
# be communicated with to control the main server. Additionally, you can
|
69
|
+
# provide an authentication token, so all requests to the control server
|
70
|
+
# will need to include that token as a query parameter. This allows for
|
71
|
+
# simple authentication.
|
72
|
+
|
73
|
+
# Check out https://github.com/puma/puma/blob/master/lib/puma/app/status.rb
|
74
|
+
# to see what the app has available.
|
75
|
+
|
76
|
+
# activate_control_app 'unix:///var/run/pumactl.sock'
|
77
|
+
|
78
|
+
daemonize
|
data/example/single.sh
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
export txtblk='\e[0;30m'
|
4
|
+
export txtred='\e[0;31m'
|
5
|
+
export txtgrn='\e[0;32m'
|
6
|
+
export txtylw='\e[0;33m'
|
7
|
+
export txtblu='\e[0;34m'
|
8
|
+
export txtpur='\e[0;35m'
|
9
|
+
export txtcyn='\e[0;36m'
|
10
|
+
export txtwht='\e[0;37m'
|
11
|
+
export clr='\e[0;0m'
|
12
|
+
|
13
|
+
[[ -f single.sh ]] || {
|
14
|
+
echo -e "${txtred}Please run this from the ./example folder.${clr}"
|
15
|
+
exit 1
|
16
|
+
}
|
17
|
+
|
18
|
+
[[ -f ../Gemfile ]] || {
|
19
|
+
echo -e "${txtred}Please choose either Puma v5 or Puma v6, by running:${clr}"
|
20
|
+
echo -e "${txtgrn}make puma-v5 or make puma-v6${clr}"
|
21
|
+
exit 2
|
22
|
+
}
|
23
|
+
|
24
|
+
echo -e "${txtblu}Ensuring your dependencies are installed...${clr}"
|
25
|
+
|
26
|
+
(
|
27
|
+
cd .. || exit 2;
|
28
|
+
bundle check || bundle install
|
29
|
+
) >/dev/null
|
30
|
+
|
31
|
+
[[ -d example ]] && cd example
|
32
|
+
|
33
|
+
pid=$(ps -ef | grep puma | grep example | awk '{print $2}')
|
34
|
+
|
35
|
+
[[ -n $pid ]] && kill $pid && sleep 1
|
36
|
+
|
37
|
+
echo -e "${txtblu}Starting Puma in Single mode.${clr}"
|
38
|
+
|
39
|
+
command="../exe/pumad -C $(pwd)/puma.rb -w 0"
|
40
|
+
echo "Executing:"
|
41
|
+
echo -e "${txtgrn}${command}${clr}"
|
42
|
+
eval "${command}"
|
43
|
+
|
44
|
+
echo "Verifying Puma is running"
|
45
|
+
|
46
|
+
output=$(mktemp)
|
47
|
+
|
48
|
+
set -e
|
49
|
+
|
50
|
+
curl http://0.0.0.0:9292/ > "${output}" 2>/dev/null
|
51
|
+
|
52
|
+
[[ $(cat ${output}) == "Hello World" ]] || {
|
53
|
+
echo -e "${txtred}Invalid response:${clr}">&2
|
54
|
+
cat ${output}
|
55
|
+
exit 3
|
56
|
+
}
|
57
|
+
|
58
|
+
echo -e "${txtgrn}Puma Daemon is running and returning the expected string.${clr}"
|
59
|
+
|
60
|
+
ps -ef | grep [p]uma
|
61
|
+
|
62
|
+
echo
|
63
|
+
|
64
|
+
|
data/exe/pumad
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
# vim: ft=ruby
|
5
|
+
|
6
|
+
lib_path = File.expand_path("#{File.dirname(__FILE__)}/../lib")
|
7
|
+
$LOAD_PATH << lib_path if File.exist?(lib_path) && !$LOAD_PATH.include?(lib_path)
|
8
|
+
|
4
9
|
require 'puma/daemon'
|
5
10
|
|
6
11
|
# If we are passing -d or --daemonize, do so
|
data/lib/puma/daemon/cli.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative '../daemon'
|
4
|
+
|
3
5
|
module Puma
|
4
6
|
module Daemon
|
5
7
|
class CLI
|
6
8
|
attr_accessor :argv, :cli
|
7
9
|
|
8
|
-
def initialize(argv = ARGV
|
10
|
+
def initialize(argv = ARGV)
|
9
11
|
self.argv = argv
|
10
|
-
self.cli = ::Puma::CLI.new(argv
|
12
|
+
self.cli = ::Puma::CLI.new(argv)
|
11
13
|
end
|
12
14
|
|
13
15
|
def run
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'version'
|
4
|
+
|
5
|
+
module Puma
|
6
|
+
module Daemon
|
7
|
+
module RunnerAdapter
|
8
|
+
class << self
|
9
|
+
def included(base)
|
10
|
+
base.class_eval do
|
11
|
+
attr_reader :options
|
12
|
+
attr_accessor :has_demonized
|
13
|
+
end
|
14
|
+
|
15
|
+
base.class_eval do
|
16
|
+
def output_header(mode)
|
17
|
+
super(mode)
|
18
|
+
|
19
|
+
daemonize! if daemon?
|
20
|
+
end
|
21
|
+
|
22
|
+
def daemon?
|
23
|
+
options[:daemon]
|
24
|
+
end
|
25
|
+
|
26
|
+
def daemonize!
|
27
|
+
return if has_demonized
|
28
|
+
|
29
|
+
log '* Puma Daemon: Demonizing...'
|
30
|
+
log "* Gem: puma-daemon v#{::Puma::Daemon::VERSION}"
|
31
|
+
log "* Gem: puma v#{::Puma::Const::VERSION}"
|
32
|
+
|
33
|
+
Process.daemon(true, true)
|
34
|
+
self.has_demonized = true
|
35
|
+
end
|
36
|
+
|
37
|
+
def log(str)
|
38
|
+
if super.respond_to?(:log)
|
39
|
+
super(str) unless str == 'Use Ctrl-C to stop'
|
40
|
+
else
|
41
|
+
puts(str)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/puma/daemon/version.rb
CHANGED
data/lib/puma/daemon.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'puma'
|
4
|
+
require 'puma/const'
|
4
5
|
require 'puma/runner'
|
5
6
|
require 'puma/single'
|
6
7
|
require 'puma/cluster'
|
@@ -8,7 +9,7 @@ require 'puma/dsl'
|
|
8
9
|
require 'puma/cli'
|
9
10
|
|
10
11
|
require 'puma/daemon/version'
|
11
|
-
require 'puma/daemon/
|
12
|
+
require 'puma/daemon/runner_adapter'
|
12
13
|
require 'puma/daemon/configuration'
|
13
14
|
require 'puma/daemon/cli'
|
14
15
|
require 'puma/daemon/dsl'
|
@@ -16,8 +17,8 @@ require 'puma/daemon/dsl'
|
|
16
17
|
module Puma
|
17
18
|
module Daemon
|
18
19
|
def self.daemonize!
|
19
|
-
::Puma::Single.include(::Puma::Daemon::
|
20
|
-
::Puma::Cluster.include(::Puma::Daemon::
|
20
|
+
::Puma::Single.include(::Puma::Daemon::RunnerAdapter)
|
21
|
+
::Puma::Cluster.include(::Puma::Daemon::RunnerAdapter)
|
21
22
|
::Puma::DSL.include(::Puma::Daemon::DSL)
|
22
23
|
::Puma::Configuration.prepend(::Puma::Daemon::Configuration)
|
23
24
|
::Puma::CLI.instance_eval { attr_reader :options }
|
data/puma-daemon.gemspec
CHANGED
@@ -26,20 +26,21 @@ Gem::Specification.new do |spec|
|
|
26
26
|
your config file.
|
27
27
|
DESCRIPTION
|
28
28
|
|
29
|
-
spec.homepage = 'https://github.com/
|
29
|
+
spec.homepage = 'https://github.com/kigster/puma-daemon'
|
30
30
|
spec.license = 'MIT'
|
31
31
|
|
32
32
|
spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
|
33
33
|
|
34
34
|
spec.metadata['homepage_uri'] = spec.homepage
|
35
|
-
spec.metadata['source_code_uri'] = 'https://github.com/
|
36
|
-
spec.metadata['changelog_uri'] = 'https://github.com/
|
35
|
+
spec.metadata['source_code_uri'] = 'https://github.com/kigster/puma-daemon'
|
36
|
+
spec.metadata['changelog_uri'] = 'https://github.com/kigster/puma-daemon/blob/master/CHANGELOG.md'
|
37
37
|
|
38
38
|
# Specify which files should be added to the gem when it is released.
|
39
39
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
40
40
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
41
41
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
42
42
|
end
|
43
|
+
|
43
44
|
spec.bindir = 'exe'
|
44
45
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
45
46
|
spec.require_paths = ['lib']
|
@@ -49,6 +50,7 @@ Gem::Specification.new do |spec|
|
|
49
50
|
|
50
51
|
spec.add_development_dependency 'asciidoctor'
|
51
52
|
spec.add_development_dependency 'codecov'
|
53
|
+
spec.add_development_dependency 'httparty'
|
52
54
|
spec.add_development_dependency 'relaxed-rubocop'
|
53
55
|
spec.add_development_dependency 'rspec-its'
|
54
56
|
spec.add_development_dependency 'rubocop'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puma-daemon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Gredeskoul
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puma
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: httparty
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: relaxed-rubocop
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -162,31 +176,38 @@ files:
|
|
162
176
|
- CHANGELOG.md
|
163
177
|
- Dockerfile.build
|
164
178
|
- Dockerfile.download
|
165
|
-
- Gemfile
|
179
|
+
- Gemfile.puma-v5
|
180
|
+
- Gemfile.puma-v6
|
166
181
|
- LICENSE.txt
|
167
182
|
- Makefile
|
168
183
|
- README.adoc
|
184
|
+
- README.pdf
|
169
185
|
- Rakefile
|
170
186
|
- bin/console
|
171
187
|
- bin/setup
|
188
|
+
- codecov.yml
|
172
189
|
- config/puma_cluster.rb
|
173
190
|
- config/puma_single.rb
|
191
|
+
- example/cluster.sh
|
192
|
+
- example/config.ru
|
193
|
+
- example/puma.rb
|
194
|
+
- example/single.sh
|
174
195
|
- exe/pumad
|
175
196
|
- lib/puma-daemon.rb
|
176
197
|
- lib/puma/daemon.rb
|
177
198
|
- lib/puma/daemon/cli.rb
|
178
199
|
- lib/puma/daemon/configuration.rb
|
179
200
|
- lib/puma/daemon/dsl.rb
|
180
|
-
- lib/puma/daemon/
|
201
|
+
- lib/puma/daemon/runner_adapter.rb
|
181
202
|
- lib/puma/daemon/version.rb
|
182
203
|
- puma-daemon.gemspec
|
183
|
-
homepage: https://github.com/
|
204
|
+
homepage: https://github.com/kigster/puma-daemon
|
184
205
|
licenses:
|
185
206
|
- MIT
|
186
207
|
metadata:
|
187
|
-
homepage_uri: https://github.com/
|
188
|
-
source_code_uri: https://github.com/
|
189
|
-
changelog_uri: https://github.com/
|
208
|
+
homepage_uri: https://github.com/kigster/puma-daemon
|
209
|
+
source_code_uri: https://github.com/kigster/puma-daemon
|
210
|
+
changelog_uri: https://github.com/kigster/puma-daemon/blob/master/CHANGELOG.md
|
190
211
|
post_install_message:
|
191
212
|
rdoc_options: []
|
192
213
|
require_paths:
|
@@ -202,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
223
|
- !ruby/object:Gem::Version
|
203
224
|
version: '0'
|
204
225
|
requirements: []
|
205
|
-
rubygems_version: 3.
|
226
|
+
rubygems_version: 3.3.22
|
206
227
|
signing_key:
|
207
228
|
specification_version: 4
|
208
229
|
summary: Restore somewhat Puma's ability to self-daemonize, since Puma 5.0 dropped
|
data/lib/puma/daemon/runner.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'version'
|
4
|
-
|
5
|
-
module Puma
|
6
|
-
module Daemon
|
7
|
-
module Runner
|
8
|
-
attr_reader :options
|
9
|
-
|
10
|
-
def redirect_io
|
11
|
-
super
|
12
|
-
|
13
|
-
daemonize! if daemon?
|
14
|
-
end
|
15
|
-
|
16
|
-
def daemon?
|
17
|
-
options[:daemon]
|
18
|
-
end
|
19
|
-
|
20
|
-
def daemonize!
|
21
|
-
log "* Puma Daemon: Daemonizing (puma-daemon v#{::Puma::Daemon::VERSION})..."
|
22
|
-
Process.daemon(true)
|
23
|
-
end
|
24
|
-
|
25
|
-
def log(str)
|
26
|
-
super(str) unless str == 'Use Ctrl-C to stop'
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|