puma 2.16.0 → 3.11.4
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 +5 -5
- data/{History.txt → History.md} +489 -70
- data/README.md +143 -174
- data/docs/architecture.md +36 -0
- data/{DEPLOYMENT.md → docs/deployment.md} +1 -1
- data/docs/images/puma-connection-flow-no-reactor.png +0 -0
- data/docs/images/puma-connection-flow.png +0 -0
- data/docs/images/puma-general-arch.png +0 -0
- data/docs/nginx.md +2 -2
- data/docs/plugins.md +28 -0
- data/docs/restart.md +39 -0
- data/docs/signals.md +56 -3
- data/docs/systemd.md +272 -0
- data/ext/puma_http11/extconf.rb +2 -0
- data/ext/puma_http11/http11_parser.c +291 -447
- data/ext/puma_http11/http11_parser.h +1 -0
- data/ext/puma_http11/http11_parser.java.rl +5 -5
- data/ext/puma_http11/http11_parser.rl +10 -9
- data/ext/puma_http11/http11_parser_common.rl +1 -1
- data/ext/puma_http11/io_buffer.c +8 -8
- data/ext/puma_http11/mini_ssl.c +64 -6
- data/ext/puma_http11/org/jruby/puma/Http11Parser.java +113 -131
- data/ext/puma_http11/org/jruby/puma/MiniSSL.java +9 -2
- data/ext/puma_http11/puma_http11.c +1 -0
- data/lib/puma/app/status.rb +9 -1
- data/lib/puma/binder.rb +90 -38
- data/lib/puma/cli.rb +134 -491
- data/lib/puma/client.rb +142 -4
- data/lib/puma/cluster.rb +132 -76
- data/lib/puma/commonlogger.rb +19 -20
- data/lib/puma/compat.rb +3 -7
- data/lib/puma/configuration.rb +206 -67
- data/lib/puma/const.rb +21 -31
- data/lib/puma/control_cli.rb +92 -103
- data/lib/puma/convenient.rb +23 -0
- data/lib/puma/daemon_ext.rb +6 -0
- data/lib/puma/detect.rb +10 -1
- data/lib/puma/dsl.rb +203 -45
- data/lib/puma/events.rb +22 -13
- data/lib/puma/io_buffer.rb +1 -1
- data/lib/puma/jruby_restart.rb +1 -2
- data/lib/puma/launcher.rb +431 -0
- data/lib/puma/minissl.rb +83 -4
- data/lib/puma/null_io.rb +19 -11
- data/lib/puma/plugin/tmp_restart.rb +34 -0
- data/lib/puma/plugin.rb +115 -0
- data/lib/puma/rack/backports/uri/common_193.rb +17 -13
- data/lib/puma/rack/builder.rb +3 -0
- data/lib/puma/rack/urlmap.rb +9 -8
- data/lib/puma/reactor.rb +18 -0
- data/lib/puma/runner.rb +43 -15
- data/lib/puma/server.rb +141 -35
- data/lib/puma/single.rb +16 -6
- data/lib/puma/state_file.rb +29 -0
- data/lib/puma/tcp_logger.rb +8 -1
- data/lib/puma/thread_pool.rb +60 -10
- data/lib/puma/util.rb +1 -5
- data/lib/puma.rb +13 -4
- data/lib/rack/handler/puma.rb +76 -29
- data/tools/jungle/README.md +12 -2
- data/tools/jungle/init.d/README.md +9 -2
- data/tools/jungle/init.d/puma +86 -59
- data/tools/jungle/init.d/run-puma +16 -1
- data/tools/jungle/rc.d/README.md +74 -0
- data/tools/jungle/rc.d/puma +61 -0
- data/tools/jungle/rc.d/puma.conf +10 -0
- data/tools/jungle/upstart/puma.conf +1 -1
- data/tools/trickletest.rb +1 -1
- metadata +28 -95
- data/COPYING +0 -55
- data/Gemfile +0 -13
- data/Manifest.txt +0 -74
- data/Rakefile +0 -158
- data/docs/config.md +0 -0
- data/lib/puma/capistrano.rb +0 -94
- data/lib/puma/rack/backports/uri/common_18.rb +0 -56
- data/lib/puma/rack/backports/uri/common_192.rb +0 -52
- data/puma.gemspec +0 -52
data/lib/rack/handler/puma.rb
CHANGED
|
@@ -1,52 +1,78 @@
|
|
|
1
1
|
require 'rack/handler'
|
|
2
|
-
require 'puma'
|
|
3
2
|
|
|
4
3
|
module Rack
|
|
5
4
|
module Handler
|
|
6
5
|
module Puma
|
|
7
6
|
DEFAULT_OPTIONS = {
|
|
8
|
-
:Host => '0.0.0.0',
|
|
9
|
-
:Port => 8080,
|
|
10
|
-
:Threads => '0:16',
|
|
11
7
|
:Verbose => false,
|
|
12
|
-
:Silent
|
|
8
|
+
:Silent => false
|
|
13
9
|
}
|
|
14
10
|
|
|
15
|
-
def self.
|
|
16
|
-
|
|
11
|
+
def self.config(app, options = {})
|
|
12
|
+
require 'puma'
|
|
13
|
+
require 'puma/configuration'
|
|
14
|
+
require 'puma/events'
|
|
15
|
+
require 'puma/launcher'
|
|
16
|
+
|
|
17
|
+
default_options = DEFAULT_OPTIONS.dup
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
# Libraries pass in values such as :Port and there is no way to determine
|
|
20
|
+
# if it is a default provided by the library or a special value provided
|
|
21
|
+
# by the user. A special key `user_supplied_options` can be passed. This
|
|
22
|
+
# contains an array of all explicitly defined user options. We then
|
|
23
|
+
# know that all other values are defaults
|
|
24
|
+
if user_supplied_options = options.delete(:user_supplied_options)
|
|
25
|
+
(options.keys - user_supplied_options).each do |k|
|
|
26
|
+
default_options[k] = options.delete(k)
|
|
27
|
+
end
|
|
20
28
|
end
|
|
21
29
|
|
|
22
|
-
|
|
23
|
-
|
|
30
|
+
conf = ::Puma::Configuration.new(options, default_options) do |user_config, file_config, default_config|
|
|
31
|
+
user_config.quiet
|
|
32
|
+
|
|
33
|
+
if options.delete(:Verbose)
|
|
34
|
+
app = Rack::CommonLogger.new(app, STDOUT)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
if options[:environment]
|
|
38
|
+
user_config.environment options[:environment]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
if options[:Threads]
|
|
42
|
+
min, max = options.delete(:Threads).split(':', 2)
|
|
43
|
+
user_config.threads min, max
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
if options[:Host] || options[:Port]
|
|
47
|
+
host = options[:Host] || default_options[:Host]
|
|
48
|
+
port = options[:Port] || default_options[:Port]
|
|
49
|
+
self.set_host_port_to_config(host, port, user_config)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
self.set_host_port_to_config(default_options[:Host], default_options[:Port], default_config)
|
|
53
|
+
|
|
54
|
+
user_config.app app
|
|
24
55
|
end
|
|
56
|
+
conf
|
|
57
|
+
end
|
|
25
58
|
|
|
26
|
-
events_hander = options[:Silent] ? ::Puma::Events.strings : ::Puma::Events.stdio
|
|
27
|
-
server = ::Puma::Server.new(app, events_hander)
|
|
28
|
-
min, max = options[:Threads].split(':', 2)
|
|
29
59
|
|
|
30
|
-
log = events_hander.stdout
|
|
31
60
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
61
|
+
def self.run(app, options = {})
|
|
62
|
+
conf = self.config(app, options)
|
|
63
|
+
|
|
64
|
+
events = options.delete(:Silent) ? ::Puma::Events.strings : ::Puma::Events.stdio
|
|
36
65
|
|
|
37
|
-
|
|
38
|
-
server.min_threads = min
|
|
39
|
-
server.max_threads = max
|
|
40
|
-
yield server if block_given?
|
|
66
|
+
launcher = ::Puma::Launcher.new(conf, :events => events)
|
|
41
67
|
|
|
68
|
+
yield launcher if block_given?
|
|
42
69
|
begin
|
|
43
|
-
|
|
70
|
+
launcher.run
|
|
44
71
|
rescue Interrupt
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
72
|
+
puts "* Gracefully stopping, waiting for requests to finish"
|
|
73
|
+
launcher.stop
|
|
74
|
+
puts "* Goodbye!"
|
|
48
75
|
end
|
|
49
|
-
|
|
50
76
|
end
|
|
51
77
|
|
|
52
78
|
def self.valid_options
|
|
@@ -57,9 +83,30 @@ module Rack
|
|
|
57
83
|
"Verbose" => "Don't report each request (default: false)"
|
|
58
84
|
}
|
|
59
85
|
end
|
|
86
|
+
private
|
|
87
|
+
def self.set_host_port_to_config(host, port, config)
|
|
88
|
+
config.clear_binds! if host || port
|
|
89
|
+
|
|
90
|
+
if host && (host[0,1] == '.' || host[0,1] == '/')
|
|
91
|
+
config.bind "unix://#{host}"
|
|
92
|
+
elsif host && host =~ /^ssl:\/\//
|
|
93
|
+
uri = URI.parse(host)
|
|
94
|
+
uri.port ||= port || ::Puma::Configuration::DefaultTCPPort
|
|
95
|
+
config.bind uri.to_s
|
|
96
|
+
else
|
|
97
|
+
|
|
98
|
+
if host
|
|
99
|
+
port ||= ::Puma::Configuration::DefaultTCPPort
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
if port
|
|
103
|
+
host ||= ::Puma::Configuration::DefaultTCPHost
|
|
104
|
+
config.port port, host
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
60
108
|
end
|
|
61
109
|
|
|
62
110
|
register :puma, Puma
|
|
63
111
|
end
|
|
64
112
|
end
|
|
65
|
-
|
data/tools/jungle/README.md
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
# Puma as a service
|
|
2
2
|
|
|
3
|
+
## Upstart
|
|
4
|
+
|
|
5
|
+
See `/tools/jungle/upstart` for Ubuntu's upstart scripts.
|
|
6
|
+
|
|
7
|
+
## Systemd
|
|
8
|
+
|
|
9
|
+
See [/docs/systemd](https://github.com/puma/puma/blob/master/docs/systemd.md).
|
|
10
|
+
|
|
3
11
|
## Init.d
|
|
4
12
|
|
|
13
|
+
Deprecatation Warning : `init.d` was replaced by `systemd` since Debian 8 and Ubuntu 16.04, you should look into [/docs/systemd](https://github.com/puma/puma/blob/master/docs/systemd.md) unless you are on an older OS.
|
|
14
|
+
|
|
5
15
|
See `/tools/jungle/init.d` for tools to use with init.d and start-stop-daemon.
|
|
6
16
|
|
|
7
|
-
##
|
|
17
|
+
## rc.d
|
|
8
18
|
|
|
9
|
-
See `/tools/jungle/
|
|
19
|
+
See `/tools/jungle/rc.d` for FreeBSD's rc.d scripts
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Puma daemon service
|
|
2
2
|
|
|
3
|
+
Deprecatation Warning : `init.d` was replaced by `systemd` since Debian 8 and Ubuntu 16.04, you should look into [/docs/systemd](https://github.com/puma/puma/blob/master/docs/systemd.md) unless you are on an older OS.
|
|
4
|
+
|
|
3
5
|
Init script to manage multiple Puma servers on the same box using start-stop-daemon.
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
@@ -22,16 +24,21 @@ Init script to manage multiple Puma servers on the same box using start-stop-dae
|
|
|
22
24
|
|
|
23
25
|
Puma apps are held in /etc/puma.conf by default. It's mainly a CSV file and every line represents one app. Here's the syntax:
|
|
24
26
|
|
|
25
|
-
app-path,user,config-file-path,log-file-path
|
|
27
|
+
app-path,user,config-file-path,log-file-path,environment-variables
|
|
26
28
|
|
|
27
29
|
You can add an instance by editing the file or running the following command:
|
|
28
30
|
|
|
29
31
|
sudo /etc/init.d/puma add /path/to/app user /path/to/app/config/puma.rb /path/to/app/log/puma.log
|
|
30
32
|
|
|
31
|
-
The config and log paths are optional parameters and default to:
|
|
33
|
+
The config and log paths, as well as the environment variables, are optional parameters and default to:
|
|
32
34
|
|
|
33
35
|
* config: /path/to/app/*config/puma.rb*
|
|
34
36
|
* log: /path/to/app/*log/puma.log*
|
|
37
|
+
* environment: (empty)
|
|
38
|
+
|
|
39
|
+
Multiple environment variables need to be separated by a semicolon, e.g.
|
|
40
|
+
|
|
41
|
+
FOO=1;BAR=2
|
|
35
42
|
|
|
36
43
|
To remove an app, simply delete the line from the config file or run:
|
|
37
44
|
|
data/tools/jungle/init.d/puma
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
# Required-Stop: $remote_fs $syslog
|
|
6
6
|
# Default-Start: 2 3 4 5
|
|
7
7
|
# Default-Stop: 0 1 6
|
|
8
|
-
# Short-Description:
|
|
9
|
-
# Description:
|
|
10
|
-
# placed in /etc/init.d.
|
|
8
|
+
# Short-Description: Puma web server
|
|
9
|
+
# Description: A ruby web server built for concurrency http://puma.io
|
|
10
|
+
# initscript to be placed in /etc/init.d.
|
|
11
11
|
### END INIT INFO
|
|
12
12
|
|
|
13
13
|
# Author: Darío Javier Cravero <dario@exordo.com>
|
|
@@ -39,17 +39,7 @@ do_start() {
|
|
|
39
39
|
log_daemon_msg "=> Running the jungle..."
|
|
40
40
|
for i in $JUNGLE; do
|
|
41
41
|
dir=`echo $i | cut -d , -f 1`
|
|
42
|
-
|
|
43
|
-
config_file=`echo $i | cut -d , -f 3`
|
|
44
|
-
if [ "$config_file" = "" ]; then
|
|
45
|
-
config_file="$dir/config/puma.rb"
|
|
46
|
-
fi
|
|
47
|
-
log_file=`echo $i | cut -d , -f 4`
|
|
48
|
-
if [ "$log_file" = "" ]; then
|
|
49
|
-
log_file="$dir/log/puma.log"
|
|
50
|
-
fi
|
|
51
|
-
environment=`echo $i | cut -d , -f 5`
|
|
52
|
-
do_start_one $dir $user $config_file $log_file $environment
|
|
42
|
+
do_start_one $dir
|
|
53
43
|
done
|
|
54
44
|
}
|
|
55
45
|
|
|
@@ -58,29 +48,42 @@ do_start_one() {
|
|
|
58
48
|
if [ -e $PIDFILE ]; then
|
|
59
49
|
PID=`cat $PIDFILE`
|
|
60
50
|
# If the puma isn't running, run it, otherwise restart it.
|
|
61
|
-
if
|
|
62
|
-
do_start_one_do $1
|
|
51
|
+
if ps -p $PID > /dev/null; then
|
|
52
|
+
do_start_one_do $1
|
|
63
53
|
else
|
|
64
54
|
do_restart_one $1
|
|
65
55
|
fi
|
|
66
56
|
else
|
|
67
|
-
do_start_one_do $1
|
|
57
|
+
do_start_one_do $1
|
|
68
58
|
fi
|
|
69
59
|
}
|
|
70
60
|
|
|
71
61
|
do_start_one_do() {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
62
|
+
i=`grep $1 $CONFIG`
|
|
63
|
+
dir=`echo $i | cut -d , -f 1`
|
|
64
|
+
user=`echo $i | cut -d , -f 2`
|
|
65
|
+
config_file=`echo $i | cut -d , -f 3`
|
|
66
|
+
if [ "$config_file" = "" ]; then
|
|
67
|
+
config_file="$dir/config/puma.rb"
|
|
68
|
+
fi
|
|
69
|
+
log_file=`echo $i | cut -d , -f 4`
|
|
70
|
+
if [ "$log_file" = "" ]; then
|
|
71
|
+
log_file="$dir/log/puma.log"
|
|
72
|
+
fi
|
|
73
|
+
environment=`echo $i | cut -d , -f 5`
|
|
74
|
+
|
|
75
|
+
log_daemon_msg "--> Woke up puma $dir"
|
|
76
|
+
log_daemon_msg "user $user"
|
|
77
|
+
log_daemon_msg "log to $log_file"
|
|
75
78
|
|
|
76
|
-
if [ ! -z "$
|
|
77
|
-
for e in $(echo "$
|
|
79
|
+
if [ ! -z "$environment" ]; then
|
|
80
|
+
for e in $(echo "$environment" | tr ';' '\n'); do
|
|
78
81
|
log_daemon_msg "environment $e"
|
|
79
82
|
v=${e%%\=*} ; eval "$e" ; export $v
|
|
80
83
|
done
|
|
81
84
|
fi
|
|
82
85
|
|
|
83
|
-
start-stop-daemon --verbose --start --chdir $
|
|
86
|
+
start-stop-daemon --verbose --start --chdir $dir --chuid $user --background --exec $RUNPUMA -- $dir $config_file $log_file
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
#
|
|
@@ -102,7 +105,7 @@ do_stop_one() {
|
|
|
102
105
|
STATEFILE=$1/tmp/puma/state
|
|
103
106
|
if [ -e $PIDFILE ]; then
|
|
104
107
|
PID=`cat $PIDFILE`
|
|
105
|
-
if
|
|
108
|
+
if ps -p $PID > /dev/null; then
|
|
106
109
|
log_daemon_msg "---> Puma $1 isn't running."
|
|
107
110
|
else
|
|
108
111
|
log_daemon_msg "---> About to kill PID `cat $PIDFILE`"
|
|
@@ -135,31 +138,41 @@ do_restart() {
|
|
|
135
138
|
#
|
|
136
139
|
do_restart_one() {
|
|
137
140
|
PIDFILE=$1/tmp/puma/pid
|
|
138
|
-
|
|
139
|
-
dir=`echo $i | cut -d , -f 1`
|
|
140
|
-
|
|
141
|
+
|
|
141
142
|
if [ -e $PIDFILE ]; then
|
|
142
143
|
log_daemon_msg "--> About to restart puma $1"
|
|
143
|
-
|
|
144
|
-
cd $1 && bundle exec pumactl --state $dir/tmp/puma/state restart
|
|
145
|
-
else
|
|
146
|
-
pumactl --state $dir/tmp/puma/state restart
|
|
147
|
-
fi
|
|
148
|
-
# kill -s USR2 `cat $PIDFILE`
|
|
144
|
+
kill -s USR2 `cat $PIDFILE`
|
|
149
145
|
# TODO Check if process exist
|
|
150
146
|
else
|
|
151
|
-
log_daemon_msg "--> Your puma was never playing... Let's get it out there first"
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
147
|
+
log_daemon_msg "--> Your puma was never playing... Let's get it out there first"
|
|
148
|
+
do_start_one $1
|
|
149
|
+
fi
|
|
150
|
+
return 0
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
#
|
|
154
|
+
# Function that phased restarts the jungle
|
|
155
|
+
#
|
|
156
|
+
do_phased_restart() {
|
|
157
|
+
for i in $JUNGLE; do
|
|
158
|
+
dir=`echo $i | cut -d , -f 1`
|
|
159
|
+
do_phased_restart_one $dir
|
|
160
|
+
done
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
#
|
|
164
|
+
# Function that sends a SIGUSR1 to the daemon/service
|
|
165
|
+
#
|
|
166
|
+
do_phased_restart_one() {
|
|
167
|
+
PIDFILE=$1/tmp/puma/pid
|
|
168
|
+
|
|
169
|
+
if [ -e $PIDFILE ]; then
|
|
170
|
+
log_daemon_msg "--> About to restart puma $1"
|
|
171
|
+
kill -s USR1 `cat $PIDFILE`
|
|
172
|
+
# TODO Check if process exist
|
|
173
|
+
else
|
|
174
|
+
log_daemon_msg "--> Your puma was never playing... Let's get it out there first"
|
|
175
|
+
do_start_one $1
|
|
163
176
|
fi
|
|
164
177
|
return 0
|
|
165
178
|
}
|
|
@@ -256,16 +269,25 @@ do_remove() {
|
|
|
256
269
|
|
|
257
270
|
config_bundler() {
|
|
258
271
|
HOME="$(eval echo ~$(id -un))"
|
|
259
|
-
|
|
272
|
+
|
|
273
|
+
if [ -d "$1/.rbenv/bin" ]; then
|
|
274
|
+
PATH="$1/.rbenv/bin:$1/.rbenv/shims:$1"
|
|
275
|
+
eval "$(rbenv init -)"
|
|
276
|
+
USE_LOCAL_BUNDLE=1
|
|
277
|
+
return 0
|
|
278
|
+
|
|
279
|
+
elif [ -d "/usr/local/rbenv/bin" ]; then
|
|
260
280
|
PATH="/usr/local/rbenv/bin:/usr/local/rbenv/shims:$PATH"
|
|
261
281
|
eval "$(rbenv init -)"
|
|
262
282
|
USE_LOCAL_BUNDLE=1
|
|
263
283
|
return 0
|
|
284
|
+
|
|
264
285
|
elif [ -d "$HOME/.rbenv/bin" ]; then
|
|
265
286
|
PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH"
|
|
266
287
|
eval "$(rbenv init -)"
|
|
267
288
|
USE_LOCAL_BUNDLE=1
|
|
268
289
|
return 0
|
|
290
|
+
|
|
269
291
|
# TODO: test rvm
|
|
270
292
|
# elif [ -f /etc/profile.d/rvm.sh ]; then
|
|
271
293
|
# source /etc/profile.d/rvm.sh
|
|
@@ -296,16 +318,7 @@ case "$1" in
|
|
|
296
318
|
else
|
|
297
319
|
i=`grep $2 $CONFIG`
|
|
298
320
|
dir=`echo $i | cut -d , -f 1`
|
|
299
|
-
|
|
300
|
-
config_file=`echo $i | cut -d , -f 3`
|
|
301
|
-
if [ "$config_file" = "" ]; then
|
|
302
|
-
config_file="$dir/config/puma.rb"
|
|
303
|
-
fi
|
|
304
|
-
log_file=`echo $i | cut -d , -f 4`
|
|
305
|
-
if [ "$log_file" = "" ]; then
|
|
306
|
-
log_file="$dir/log/puma.log"
|
|
307
|
-
fi
|
|
308
|
-
do_start_one $dir $user $config_file $log_file
|
|
321
|
+
do_start_one $dir
|
|
309
322
|
fi
|
|
310
323
|
case "$?" in
|
|
311
324
|
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
|
@@ -355,9 +368,23 @@ case "$1" in
|
|
|
355
368
|
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
|
356
369
|
esac
|
|
357
370
|
;;
|
|
371
|
+
phased-restart)
|
|
372
|
+
log_daemon_msg "Restarting (phased) $DESC" "$NAME"
|
|
373
|
+
if [ "$#" -eq 1 ]; then
|
|
374
|
+
do_phased_restart
|
|
375
|
+
else
|
|
376
|
+
i=`grep $2 $CONFIG`
|
|
377
|
+
dir=`echo $i | cut -d , -f 1`
|
|
378
|
+
do_phased_restart_one $dir
|
|
379
|
+
fi
|
|
380
|
+
case "$?" in
|
|
381
|
+
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
|
382
|
+
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
|
383
|
+
esac
|
|
384
|
+
;;
|
|
358
385
|
add)
|
|
359
386
|
if [ "$#" -lt 3 ]; then
|
|
360
|
-
echo "Please,
|
|
387
|
+
echo "Please, specify the app's directory and the user that will run it at least."
|
|
361
388
|
echo " Usage: $SCRIPTNAME add /path/to/app user /path/to/app/config/puma.rb /path/to/app/config/log/puma.log"
|
|
362
389
|
echo " config and log are optionals."
|
|
363
390
|
exit 1
|
|
@@ -383,11 +410,11 @@ case "$1" in
|
|
|
383
410
|
;;
|
|
384
411
|
*)
|
|
385
412
|
echo "Usage:" >&2
|
|
386
|
-
echo " Run the jungle: $SCRIPTNAME {start|stop|status|restart}" >&2
|
|
413
|
+
echo " Run the jungle: $SCRIPTNAME {start|stop|status|restart|phased-restart}" >&2
|
|
387
414
|
echo " Add a Puma: $SCRIPTNAME add /path/to/app user /path/to/app/config/puma.rb /path/to/app/config/log/puma.log"
|
|
388
415
|
echo " config and log are optionals."
|
|
389
416
|
echo " Remove a Puma: $SCRIPTNAME remove /path/to/app"
|
|
390
|
-
echo " On a Puma: $SCRIPTNAME {start|stop|status|restart} PUMA-NAME" >&2
|
|
417
|
+
echo " On a Puma: $SCRIPTNAME {start|stop|status|restart|phased-restart} PUMA-NAME" >&2
|
|
391
418
|
exit 3
|
|
392
419
|
;;
|
|
393
420
|
esac
|
|
@@ -1,3 +1,18 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# on system boot, and root have no rbenv installed,
|
|
4
|
+
# after start-stop-daemon switched to current user, we have to init rbenv
|
|
5
|
+
if [ -d "$HOME/.rbenv/bin" ]; then
|
|
6
|
+
PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH"
|
|
7
|
+
eval "$(rbenv init -)"
|
|
8
|
+
elif [ -d "/usr/local/rbenv/bin" ]; then
|
|
9
|
+
PATH="/usr/local/rbenv/bin:/usr/local/rbenv/shims:$PATH"
|
|
10
|
+
eval "$(rbenv init -)"
|
|
11
|
+
elif [ -f /usr/local/rvm/scripts/rvm ]; then
|
|
12
|
+
source /etc/profile.d/rvm.sh
|
|
13
|
+
elif [ -f "$HOME/.rvm/scripts/rvm" ]; then
|
|
14
|
+
source "$HOME/.rvm/scripts/rvm"
|
|
15
|
+
fi
|
|
16
|
+
|
|
2
17
|
app=$1; config=$2; log=$3;
|
|
3
|
-
cd $app && exec bundle exec puma -C $config
|
|
18
|
+
cd $app && exec bundle exec puma -C $config >> $log 2>&1
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Puma as a service using rc.d
|
|
2
|
+
|
|
3
|
+
Manage multilpe Puma servers as services on one box using FreeBSD's rc.d service.
|
|
4
|
+
|
|
5
|
+
## Dependencies
|
|
6
|
+
|
|
7
|
+
* `jq` - a command-line json parser is needed to parse the json in the config file
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
# Copy the puma script to the rc.d directory (make sure everyone has read/execute perms)
|
|
12
|
+
sudo cp puma /usr/local/etc/rc.d/
|
|
13
|
+
|
|
14
|
+
# Create an empty configuration file
|
|
15
|
+
sudo touch /usr/local/etc/puma.conf
|
|
16
|
+
|
|
17
|
+
# Enable the puma service
|
|
18
|
+
sudo echo 'puma_enable="YES"' >> /etc/rc.conf
|
|
19
|
+
|
|
20
|
+
## Managing the jungle
|
|
21
|
+
|
|
22
|
+
Puma apps are referenced in /usr/local/etc/puma.conf by default.
|
|
23
|
+
|
|
24
|
+
Start the jungle running:
|
|
25
|
+
|
|
26
|
+
`service puma start`
|
|
27
|
+
|
|
28
|
+
This script will run at boot time.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
You can also stop the jungle (stops ALL puma instances) by running:
|
|
32
|
+
|
|
33
|
+
`service puma stop`
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
To restart the jungle:
|
|
37
|
+
|
|
38
|
+
`service puma restart`
|
|
39
|
+
|
|
40
|
+
## Conventions
|
|
41
|
+
|
|
42
|
+
* The script expects:
|
|
43
|
+
* a config file to exist under `config/puma.rb` in your app. E.g.: `/home/apps/my-app/config/puma.rb`.
|
|
44
|
+
|
|
45
|
+
You can always change those defaults by editing the scripts.
|
|
46
|
+
|
|
47
|
+
## Here's what a minimal app's config file should have
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
{
|
|
51
|
+
"servers" : [
|
|
52
|
+
{
|
|
53
|
+
"dir": "/path/to/rails/project",
|
|
54
|
+
"user": "deploy-user",
|
|
55
|
+
"ruby_version": "ruby.version",
|
|
56
|
+
"ruby_env": "rbenv"
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Before starting...
|
|
63
|
+
|
|
64
|
+
You need to customise `puma.conf` to:
|
|
65
|
+
|
|
66
|
+
* Set the right user your app should be running on unless you want root to execute it!
|
|
67
|
+
* Set the directory of the app
|
|
68
|
+
* Set the ruby version to execute
|
|
69
|
+
* Set the ruby environment (currently set to rbenv, since that is the only ruby environment currently supported)
|
|
70
|
+
* Add additional server instances following the scheme in the example
|
|
71
|
+
|
|
72
|
+
## Notes:
|
|
73
|
+
|
|
74
|
+
Only rbenv is currently supported.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
#
|
|
3
|
+
|
|
4
|
+
# PROVIDE: puma
|
|
5
|
+
|
|
6
|
+
. /etc/rc.subr
|
|
7
|
+
|
|
8
|
+
name="puma"
|
|
9
|
+
start_cmd="puma_start"
|
|
10
|
+
stop_cmd="puma_stop"
|
|
11
|
+
restart_cmd="puma_restart"
|
|
12
|
+
rcvar=puma_enable
|
|
13
|
+
required_files=/usr/local/etc/puma.conf
|
|
14
|
+
|
|
15
|
+
puma_start()
|
|
16
|
+
{
|
|
17
|
+
server_count=$(/usr/local/bin/jq ".servers[] .ruby_env" /usr/local/etc/puma.conf | wc -l)
|
|
18
|
+
i=0
|
|
19
|
+
while [ "$i" -lt "$server_count" ]; do
|
|
20
|
+
rb_env=$(/usr/local/bin/jq -r ".servers[$i].ruby_env" /usr/local/etc/puma.conf)
|
|
21
|
+
dir=$(/usr/local/bin/jq -r ".servers[$i].dir" /usr/local/etc/puma.conf)
|
|
22
|
+
user=$(/usr/local/bin/jq -r ".servers[$i].user" /usr/local/etc/puma.conf)
|
|
23
|
+
rb_ver=$(/usr/local/bin/jq -r ".servers[$i].ruby_version" /usr/local/etc/puma.conf)
|
|
24
|
+
case $rb_env in
|
|
25
|
+
"rbenv")
|
|
26
|
+
su - $user -c "cd $dir && rbenv shell $rb_ver && bundle exec puma -C $dir/config/puma.rb -d"
|
|
27
|
+
;;
|
|
28
|
+
*)
|
|
29
|
+
;;
|
|
30
|
+
esac
|
|
31
|
+
i=$(( i + 1 ))
|
|
32
|
+
done
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
puma_stop()
|
|
36
|
+
{
|
|
37
|
+
pkill ruby
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
puma_restart()
|
|
41
|
+
{
|
|
42
|
+
server_count=$(/usr/local/bin/jq ".servers[] .ruby_env" /usr/local/etc/puma.conf | wc -l)
|
|
43
|
+
i=0
|
|
44
|
+
while [ "$i" -lt "$server_count" ]; do
|
|
45
|
+
rb_env=$(/usr/local/bin/jq -r ".servers[$i].ruby_env" /usr/local/etc/puma.conf)
|
|
46
|
+
dir=$(/usr/local/bin/jq -r ".servers[$i].dir" /usr/local/etc/puma.conf)
|
|
47
|
+
user=$(/usr/local/bin/jq -r ".servers[$i].user" /usr/local/etc/puma.conf)
|
|
48
|
+
rb_ver=$(/usr/local/bin/jq -r ".servers[$i].ruby_version" /usr/local/etc/puma.conf)
|
|
49
|
+
case $rb_env in
|
|
50
|
+
"rbenv")
|
|
51
|
+
su - $user -c "cd $dir && pkill ruby && rbenv shell $ruby_version && bundle exec puma -C $dir/config/puma.rb -d"
|
|
52
|
+
;;
|
|
53
|
+
*)
|
|
54
|
+
;;
|
|
55
|
+
esac
|
|
56
|
+
i=$(( i + 1 ))
|
|
57
|
+
done
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
load_rc_config $name
|
|
61
|
+
run_rc_command "$1"
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
# allows you to manage multiple Puma instances with
|
|
5
5
|
# Upstart, Ubuntu's native service management tool.
|
|
6
6
|
#
|
|
7
|
-
# See
|
|
7
|
+
# See puma-manager.conf for how to manage all Puma instances at once.
|
|
8
8
|
#
|
|
9
9
|
# Save this config as /etc/init/puma.conf then manage puma with:
|
|
10
10
|
# sudo start puma app=PATH_TO_APP
|
data/tools/trickletest.rb
CHANGED