ed-precompiled_puma 7.0.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.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/History.md +3172 -0
  3. data/LICENSE +29 -0
  4. data/README.md +477 -0
  5. data/bin/puma +10 -0
  6. data/bin/puma-wild +25 -0
  7. data/bin/pumactl +12 -0
  8. data/docs/architecture.md +74 -0
  9. data/docs/compile_options.md +55 -0
  10. data/docs/deployment.md +102 -0
  11. data/docs/fork_worker.md +41 -0
  12. data/docs/images/puma-connection-flow-no-reactor.png +0 -0
  13. data/docs/images/puma-connection-flow.png +0 -0
  14. data/docs/images/puma-general-arch.png +0 -0
  15. data/docs/java_options.md +54 -0
  16. data/docs/jungle/README.md +9 -0
  17. data/docs/jungle/rc.d/README.md +74 -0
  18. data/docs/jungle/rc.d/puma +61 -0
  19. data/docs/jungle/rc.d/puma.conf +10 -0
  20. data/docs/kubernetes.md +80 -0
  21. data/docs/nginx.md +80 -0
  22. data/docs/plugins.md +42 -0
  23. data/docs/rails_dev_mode.md +28 -0
  24. data/docs/restart.md +65 -0
  25. data/docs/signals.md +98 -0
  26. data/docs/stats.md +148 -0
  27. data/docs/systemd.md +253 -0
  28. data/docs/testing_benchmarks_local_files.md +150 -0
  29. data/docs/testing_test_rackup_ci_files.md +36 -0
  30. data/ext/puma_http11/PumaHttp11Service.java +17 -0
  31. data/ext/puma_http11/ext_help.h +15 -0
  32. data/ext/puma_http11/extconf.rb +65 -0
  33. data/ext/puma_http11/http11_parser.c +1057 -0
  34. data/ext/puma_http11/http11_parser.h +65 -0
  35. data/ext/puma_http11/http11_parser.java.rl +145 -0
  36. data/ext/puma_http11/http11_parser.rl +149 -0
  37. data/ext/puma_http11/http11_parser_common.rl +54 -0
  38. data/ext/puma_http11/mini_ssl.c +852 -0
  39. data/ext/puma_http11/no_ssl/PumaHttp11Service.java +15 -0
  40. data/ext/puma_http11/org/jruby/puma/Http11.java +257 -0
  41. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +455 -0
  42. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +509 -0
  43. data/ext/puma_http11/puma_http11.c +507 -0
  44. data/lib/puma/app/status.rb +96 -0
  45. data/lib/puma/binder.rb +511 -0
  46. data/lib/puma/cli.rb +245 -0
  47. data/lib/puma/client.rb +720 -0
  48. data/lib/puma/cluster/worker.rb +182 -0
  49. data/lib/puma/cluster/worker_handle.rb +127 -0
  50. data/lib/puma/cluster.rb +635 -0
  51. data/lib/puma/cluster_accept_loop_delay.rb +91 -0
  52. data/lib/puma/commonlogger.rb +115 -0
  53. data/lib/puma/configuration.rb +452 -0
  54. data/lib/puma/const.rb +307 -0
  55. data/lib/puma/control_cli.rb +320 -0
  56. data/lib/puma/detect.rb +47 -0
  57. data/lib/puma/dsl.rb +1480 -0
  58. data/lib/puma/error_logger.rb +115 -0
  59. data/lib/puma/events.rb +72 -0
  60. data/lib/puma/io_buffer.rb +50 -0
  61. data/lib/puma/jruby_restart.rb +11 -0
  62. data/lib/puma/json_serialization.rb +96 -0
  63. data/lib/puma/launcher/bundle_pruner.rb +104 -0
  64. data/lib/puma/launcher.rb +496 -0
  65. data/lib/puma/log_writer.rb +147 -0
  66. data/lib/puma/minissl/context_builder.rb +96 -0
  67. data/lib/puma/minissl.rb +463 -0
  68. data/lib/puma/null_io.rb +101 -0
  69. data/lib/puma/plugin/systemd.rb +90 -0
  70. data/lib/puma/plugin/tmp_restart.rb +36 -0
  71. data/lib/puma/plugin.rb +111 -0
  72. data/lib/puma/rack/builder.rb +297 -0
  73. data/lib/puma/rack/urlmap.rb +93 -0
  74. data/lib/puma/rack_default.rb +24 -0
  75. data/lib/puma/reactor.rb +140 -0
  76. data/lib/puma/request.rb +701 -0
  77. data/lib/puma/runner.rb +211 -0
  78. data/lib/puma/sd_notify.rb +146 -0
  79. data/lib/puma/server.rb +734 -0
  80. data/lib/puma/single.rb +72 -0
  81. data/lib/puma/state_file.rb +69 -0
  82. data/lib/puma/thread_pool.rb +402 -0
  83. data/lib/puma/util.rb +134 -0
  84. data/lib/puma.rb +93 -0
  85. data/lib/rack/handler/puma.rb +144 -0
  86. data/tools/Dockerfile +18 -0
  87. data/tools/trickletest.rb +44 -0
  88. metadata +152 -0
data/docs/restart.md ADDED
@@ -0,0 +1,65 @@
1
+ Puma provides three distinct kinds of restart operations, each for different use cases. This document describes "hot restarts" and "phased restarts." The third kind of restart operation is called "refork" and is described in the documentation for [`fork_worker`](fork_worker.md).
2
+
3
+ ## Hot restart
4
+
5
+ To perform a "hot" restart, Puma performs an `exec` operation to start the process up again, so no memory is shared between the old process and the new process. As a result, it is safe to issue a restart at any place where you would manually stop Puma and start it again. In particular, it is safe to upgrade Puma itself using a hot restart.
6
+
7
+ If the new process is unable to load, it will simply exit. You should therefore run Puma under a process monitor when using it in production.
8
+
9
+ ### How-to
10
+
11
+ Any of the following will cause a Puma server to perform a hot restart:
12
+
13
+ * Send the `puma` process the `SIGUSR2` signal
14
+ * Issue a `GET` request to the Puma status/control server with the path `/restart`
15
+ * Issue `pumactl restart` (this uses the control server method if available, otherwise sends the `SIGUSR2` signal to the process)
16
+
17
+ ### Supported configurations
18
+
19
+ * Works in cluster mode and single mode
20
+ * Supported on all platforms
21
+
22
+ ### Client experience
23
+
24
+ * All platforms: clients with an in-flight request are served responses before the connection is closed gracefully. Puma gracefully disconnects any idle HTTP persistent connections before restarting.
25
+ * On MRI or TruffleRuby on Linux and BSD: Clients who connect just before the server restarts may experience increased latency while the server stops and starts again, but their connections will not be closed prematurely.
26
+ * On Windows and JRuby: Clients who connect just before a restart may experience "connection reset" errors.
27
+
28
+ ### Additional notes
29
+
30
+ * The newly started Puma process changes its current working directory to the directory specified by the `directory` option. If `directory` is set to symlink, this is automatically re-evaluated, so this mechanism can be used to upgrade the application.
31
+ * Only one version of the application is running at a time.
32
+ * `before_restart` is invoked just before the server shuts down. This can be used to clean up resources (like long-lived database connections) gracefully. Since Ruby 2.0, it is not typically necessary to explicitly close file descriptors on restart. This is because any file descriptor opened by Ruby will have the `FD_CLOEXEC` flag set, meaning that file descriptors are closed on `exec`. `before_restart` is useful, though, if your application needs to perform any more graceful protocol-specific shutdown procedures before closing connections.
33
+
34
+ ## Phased restart
35
+
36
+ Phased restarts replace all running workers in a Puma cluster. This is a useful way to upgrade the application that Puma is serving gracefully. A phased restart works by first killing an old worker, then starting a new worker, waiting until the new worker has successfully started before proceeding to the next worker. This process continues until all workers are replaced. The master process is not restarted.
37
+
38
+ ### How-to
39
+
40
+ Any of the following will cause a Puma server to perform a phased restart:
41
+
42
+ * Send the `puma` process the `SIGUSR1` signal
43
+ * Issue a `GET` request to the Puma status/control server with the path `/phased-restart`
44
+ * Issue `pumactl phased-restart` (this uses the control server method if available, otherwise sends the `SIGUSR1` signal to the process)
45
+
46
+ ### Supported configurations
47
+
48
+ * Works in cluster mode only
49
+ * To support upgrading the application that Puma is serving, ensure `prune_bundler` is enabled and that `preload_app!` is disabled
50
+ * Supported on all platforms where cluster mode is supported
51
+
52
+ ### Client experience
53
+
54
+ * In-flight requests are always served responses before the connection is closed gracefully
55
+ * Idle persistent connections are gracefully disconnected
56
+ * New connections are not lost, and clients will not experience any increase in latency (as long as the number of configured workers is greater than one)
57
+
58
+ ### Additional notes
59
+
60
+ * When a phased restart begins, the Puma master process changes its current working directory to the directory specified by the `directory` option. If `directory` is set to symlink, this is automatically re-evaluated, so this mechanism can be used to upgrade the application.
61
+ * On a single server, it's possible that two versions of the application are running concurrently during a phased restart.
62
+ * `before_restart` is not invoked
63
+ * Phased restarts can be slow for Puma clusters with many workers. Hot restarts often complete more quickly, but at the cost of increased latency during the restart.
64
+ * Phased restarts cannot be used to upgrade any gems loaded by the Puma master process, including `puma` itself, anything in `extra_runtime_dependencies`, or dependencies thereof. Upgrading other gems is safe.
65
+ * If you remove the gems from old releases as part of your deployment strategy, there are additional considerations. Do not put any gems into `extra_runtime_dependencies` that have native extensions or have dependencies that have native extensions (one common example is `puma_worker_killer` and its dependency on `ffi`). Workers will fail on boot during a phased restart. The underlying issue is recorded in [an issue on the rubygems project](https://github.com/rubygems/rubygems/issues/4004). Hot restarts are your only option here if you need these dependencies.
data/docs/signals.md ADDED
@@ -0,0 +1,98 @@
1
+ The [unix signal](https://en.wikipedia.org/wiki/Unix_signal) is a method of sending messages between [processes](https://en.wikipedia.org/wiki/Process_(computing)). When a signal is sent, the operating system interrupts the target process's normal flow of execution. There are standard signals that are used to stop a process, but there are also custom signals that can be used for other purposes. This document is an attempt to list all supported signals that Puma will respond to. In general, signals need only be sent to the master process of a cluster.
2
+
3
+ ## Sending Signals
4
+
5
+ If you are new to signals, it can be helpful to see how they are used. When a process starts in a *nix-like operating system, it will have a [PID - or process identifier](https://en.wikipedia.org/wiki/Process_identifier) that can be used to send signals to the process. For demonstration, we will create an infinitely running process by tailing a file:
6
+
7
+ ```sh
8
+ $ echo "foo" >> my.log
9
+ $ irb
10
+ > pid = Process.spawn 'tail -f my.log'
11
+ ```
12
+
13
+ From here, we can see that the tail process is running by using the `ps` command:
14
+
15
+ ```sh
16
+ $ ps aux | grep tail
17
+ schneems 87152 0.0 0.0 2432772 492 s032 S+ 12:46PM 0:00.00 tail -f my.log
18
+ ```
19
+
20
+ You can send a signal in Ruby using the [Process module](https://docs.ruby-lang.org/en/master/Process.html#method-c-kill):
21
+
22
+ ```
23
+ $ irb
24
+ > puts pid
25
+ => 87152
26
+ Process.detach(pid) # https://docs.ruby-lang.org/en/master/Process.html#method-c-detach
27
+ Process.kill("TERM", pid)
28
+ ```
29
+
30
+ Now you will see via `ps` that there is no more `tail` process. Sometimes when referring to signals, the `SIG` prefix will be used. For example, `SIGTERM` is equivalent to sending `TERM` via `Process.kill`.
31
+
32
+ ## Puma Signals
33
+
34
+ Puma cluster responds to these signals:
35
+
36
+ - `TTIN` increment the worker count by 1
37
+ - `TTOU` decrement the worker count by 1
38
+ - `TERM` send `TERM` to worker. The worker will attempt to finish then exit.
39
+ - `USR2` restart workers. This also reloads the Puma configuration file, if there is one.
40
+ - `USR1` restart workers in phases, a rolling restart. This will not reload the configuration file.
41
+ - `HUP ` reopen log files defined in stdout_redirect configuration parameter. If there is no stdout_redirect option provided, it will behave like `INT`
42
+ - `INT ` equivalent of sending Ctrl-C to cluster. Puma will attempt to finish then exit.
43
+ - `CHLD`
44
+ - `URG ` refork workers in phases from worker 0 if `fork_workers` option is enabled.
45
+ - `INFO` print backtraces of all puma threads
46
+
47
+ ## Callbacks order in case of different signals
48
+
49
+ ### Start application
50
+
51
+ ```
52
+ puma configuration file reloaded, if there is one
53
+ * Pruning Bundler environment
54
+ puma configuration file reloaded, if there is one
55
+
56
+ before_fork
57
+ before_worker_fork
58
+ after_worker_fork
59
+
60
+ Gemfile in context
61
+
62
+ before_worker_boot
63
+
64
+ Code of the app is loaded and running
65
+ ```
66
+
67
+ ### Send USR2
68
+
69
+ ```
70
+ before_worker_shutdown
71
+ before_restart
72
+
73
+ puma configuration file reloaded, if there is one
74
+
75
+ before_fork
76
+ before_worker_fork
77
+ after_worker_fork
78
+
79
+ Gemfile in context
80
+
81
+ before_worker_boot
82
+
83
+ Code of the app is loaded and running
84
+ ```
85
+
86
+ ### Send USR1
87
+
88
+ ```
89
+ before_worker_shutdown
90
+ before_worker_fork
91
+ after_worker_fork
92
+
93
+ Gemfile in context
94
+
95
+ before_worker_boot
96
+
97
+ Code of the app is loaded and running
98
+ ```
data/docs/stats.md ADDED
@@ -0,0 +1,148 @@
1
+ ## Accessing stats
2
+
3
+ Stats can be accessed in two ways:
4
+
5
+ ### control server
6
+
7
+ `$ pumactl stats` or `GET /stats`
8
+
9
+ [Read more about `pumactl` and the control server in the README.](https://github.com/puma/puma#controlstatus-server).
10
+
11
+ ### Puma.stats
12
+
13
+ `Puma.stats` produces a JSON string. `Puma.stats_hash` produces a ruby hash.
14
+
15
+ #### in single mode
16
+
17
+ Invoke `Puma.stats` anywhere in runtime, e.g. in a rails initializer:
18
+
19
+ ```ruby
20
+ # config/initializers/puma_stats.rb
21
+
22
+ Thread.new do
23
+ loop do
24
+ sleep 30
25
+ puts Puma.stats
26
+ end
27
+ end
28
+ ```
29
+
30
+ #### in cluster mode
31
+
32
+ Invoke `Puma.stats` from the master process
33
+
34
+ ```ruby
35
+ # config/puma.rb
36
+
37
+ before_fork do
38
+ Thread.new do
39
+ loop do
40
+ puts Puma.stats
41
+ sleep 30
42
+ end
43
+ end
44
+ end
45
+ ```
46
+
47
+
48
+ ## Explanation of stats
49
+
50
+ `Puma.stats` returns different information and a different structure depending on if Puma is in single vs. cluster mode. There is one top-level attribute that is common to both modes:
51
+
52
+ * started_at: when Puma was started
53
+
54
+ ### single mode and individual workers in cluster mode
55
+
56
+ When Puma runs in single mode, these stats are available at the top level. When Puma runs in cluster mode, these stats are available within the `worker_status` array in a hash labeled `last_status`, in an array of hashes where one hash represents each worker.
57
+
58
+ * backlog: requests that are waiting for an available thread to be available. if this is frequently above 0, you need more capacity.
59
+ * running: how many threads are spawned. A spawned thread may be busy processing a request or waiting for a new request. If `min_threads` and `max_threads` are set to the same number,
60
+ this will be a never-changing number (other than rare cases when a thread dies, etc).
61
+ * busy_threads: `running` - `how many threads are waiting to receive work` + `how many requests are waiting for a thread to pick them up`.
62
+ this is a "wholistic" stat reflecting the overall current state of work to be done and the capacity to do it.
63
+ * pool_capacity: `how many threads are waiting to receive work` + `max_threads` - `running`. In a typical configuration where `min_threads`
64
+ and `max_threads` are configured to the same number, this is simply `how many threads are waiting to receive work`. This number exists only as a stat
65
+ and is not used for any internal decisions, unlike `busy_theads`, which is usually a more useful stat.
66
+ * max_threads: the maximum number of threads Puma is configured to spool per worker
67
+ * requests_count: the number of requests this worker has served since starting
68
+ * reactor_max: the maximum observed number of requests held in Puma's "reactor" which is used for asyncronously buffering request bodies. This stat is reset on every call, so it's the maximum value observed since the last stat call.
69
+ * backlog_max: the maximum number of requests that have been fully buffered by the reactor and placed in a ready queue, but have not yet been picked up by a server thread. This stat is reset on every call, so it's the maximum value observed since the last stat call.
70
+
71
+ ### cluster mode
72
+
73
+ * phase: which phase of restart the process is in, during [phased restart](https://github.com/puma/puma/blob/master/docs/restart.md)
74
+ * workers: ??
75
+ * booted_workers: how many workers currently running?
76
+ * old_workers: ??
77
+ * worker_status: array of hashes of info for each worker (see below)
78
+
79
+ ### worker status
80
+
81
+ * started_at: when the worker started
82
+ * pid: the process id of the worker process
83
+ * index: each worker gets a number. if Puma is configured to have 3 workers, then this will be 0, 1, or 2
84
+ * booted: if it's done booting [?]
85
+ * last_checkin: Last time the worker responded to the master process' heartbeat check.
86
+ * last_status: a hash of info about the worker's state handling requests. See the explanation for this in "single mode and individual workers in cluster mode" section above.
87
+
88
+
89
+ ## Examples
90
+
91
+ Here are two example stats hashes produced by `Puma.stats`:
92
+
93
+ ### single
94
+
95
+ ```json
96
+ {
97
+ "started_at": "2021-01-14T07:12:35Z",
98
+ "backlog": 0,
99
+ "running": 5,
100
+ "pool_capacity": 5,
101
+ "max_threads": 5,
102
+ "requests_count": 3
103
+ }
104
+ ```
105
+
106
+ ### cluster
107
+
108
+ ```json
109
+ {
110
+ "started_at": "2021-01-14T07:09:17Z",
111
+ "workers": 2,
112
+ "phase": 0,
113
+ "booted_workers": 2,
114
+ "old_workers": 0,
115
+ "worker_status": [
116
+ {
117
+ "started_at": "2021-01-14T07:09:24Z",
118
+ "pid": 64136,
119
+ "index": 0,
120
+ "phase": 0,
121
+ "booted": true,
122
+ "last_checkin": "2021-01-14T07:11:09Z",
123
+ "last_status": {
124
+ "backlog": 0,
125
+ "running": 5,
126
+ "pool_capacity": 5,
127
+ "max_threads": 5,
128
+ "requests_count": 2
129
+ }
130
+ },
131
+ {
132
+ "started_at": "2021-01-14T07:09:24Z",
133
+ "pid": 64137,
134
+ "index": 1,
135
+ "phase": 0,
136
+ "booted": true,
137
+ "last_checkin": "2021-01-14T07:11:09Z",
138
+ "last_status": {
139
+ "backlog": 0,
140
+ "running": 5,
141
+ "pool_capacity": 5,
142
+ "max_threads": 5,
143
+ "requests_count": 1
144
+ }
145
+ }
146
+ ]
147
+ }
148
+ ```
data/docs/systemd.md ADDED
@@ -0,0 +1,253 @@
1
+ # systemd
2
+
3
+ [systemd](https://www.freedesktop.org/wiki/Software/systemd/) is a commonly
4
+ available init system (PID 1) on many Linux distributions. It offers process
5
+ monitoring (including automatic restarts) and other useful features for running
6
+ Puma in production.
7
+
8
+ ## Service Configuration
9
+
10
+ Below is a sample puma.service configuration file for systemd, which can be
11
+ copied or symlinked to `/etc/systemd/system/puma.service`, or if desired, using
12
+ an application or instance-specific name.
13
+
14
+ Note that this uses the systemd preferred "simple" type where the start command
15
+ remains running in the foreground (does not fork and exit).
16
+
17
+ ~~~~ ini
18
+ [Unit]
19
+ Description=Puma HTTP Server
20
+ After=network.target
21
+
22
+ # Uncomment for socket activation (see below)
23
+ # Requires=puma.socket
24
+
25
+ [Service]
26
+ # Puma supports systemd's `Type=notify` and watchdog service
27
+ # monitoring, as of Puma 5.1 or later.
28
+ # On earlier versions of Puma or JRuby, change this to `Type=simple` and remove
29
+ # the `WatchdogSec` line.
30
+ Type=notify
31
+
32
+ # If your Puma process locks up, systemd's watchdog will restart it within seconds.
33
+ WatchdogSec=10
34
+
35
+ # Preferably configure a non-privileged user
36
+ # User=
37
+
38
+ # The path to your application code root directory.
39
+ # Also replace the "<YOUR_APP_PATH>" placeholders below with this path.
40
+ # Example /home/username/myapp
41
+ WorkingDirectory=<YOUR_APP_PATH>
42
+
43
+ # Helpful for debugging socket activation, etc.
44
+ # Environment=PUMA_DEBUG=1
45
+
46
+ # SystemD will not run puma even if it is in your path. You must specify
47
+ # an absolute URL to puma. For example /usr/local/bin/puma
48
+ # Alternatively, create a binstub with `bundle binstubs puma --path ./sbin` in the WorkingDirectory
49
+ ExecStart=/<FULLPATH>/bin/puma -C <YOUR_APP_PATH>/puma.rb
50
+
51
+ # Variant: Rails start.
52
+ # ExecStart=/<FULLPATH>/bin/puma -C <YOUR_APP_PATH>/config/puma.rb ../config.ru
53
+
54
+ # Variant: Use `bundle exec puma` instead of binstub
55
+ # Variant: Specify directives inline.
56
+ # ExecStart=/<FULLPATH>/puma -b tcp://0.0.0.0:9292 -b ssl://0.0.0.0:9293?key=key.pem&cert=cert.pem
57
+
58
+
59
+ Restart=always
60
+
61
+ [Install]
62
+ WantedBy=multi-user.target
63
+ ~~~~
64
+
65
+ See
66
+ [systemd.exec](https://www.freedesktop.org/software/systemd/man/systemd.exec.html)
67
+ for additional details.
68
+
69
+ ## Socket Activation
70
+
71
+ systemd and Puma also support socket activation, where systemd opens the
72
+ listening socket(s) in advance and provides them to the Puma master process on
73
+ startup. Among other advantages, this keeps listening sockets open across puma
74
+ restarts and achieves graceful restarts, including when upgraded Puma, and is
75
+ compatible with both cluster mode and application preload.
76
+
77
+ **Note:** Any wrapper scripts which `exec`, or other indirections in `ExecStart`
78
+ may result in activated socket file descriptors being closed before reaching the
79
+ puma master process.
80
+
81
+ **Note:** Socket activation doesn't currently work on JRuby. This is tracked in
82
+ [#1367].
83
+
84
+ Configure one or more `ListenStream` sockets in a companion `*.socket` unit file
85
+ to use socket activation. Also, uncomment the associated `Requires` directive
86
+ for the socket unit in the service file (see above.) Here is a sample
87
+ puma.socket, matching the ports used in the above puma.service:
88
+
89
+ ~~~~ ini
90
+ [Unit]
91
+ Description=Puma HTTP Server Accept Sockets
92
+
93
+ [Socket]
94
+ ListenStream=0.0.0.0:9292
95
+ ListenStream=0.0.0.0:9293
96
+
97
+ # AF_UNIX domain socket
98
+ # SocketUser, SocketGroup, etc. may be needed for Unix domain sockets
99
+ # ListenStream=/run/puma.sock
100
+
101
+ # Socket options matching Puma defaults
102
+ ReusePort=true
103
+ Backlog=1024
104
+ # Enable this if you're using Puma with the "low_latency" option, read more in Puma DSL docs and systemd docs:
105
+ # https://www.freedesktop.org/software/systemd/man/latest/systemd.socket.html#NoDelay=
106
+ # NoDelay=true
107
+
108
+ [Install]
109
+ WantedBy=sockets.target
110
+ ~~~~
111
+
112
+ See
113
+ [systemd.socket](https://www.freedesktop.org/software/systemd/man/systemd.socket.html)
114
+ for additional configuration details.
115
+
116
+ Note that the above configurations will work with Puma in either single process
117
+ or cluster mode.
118
+
119
+ ### Sockets and symlinks
120
+
121
+ When using releases folders, you should set the socket path using the shared
122
+ folder path (ex. `/srv/projet/shared/tmp/puma.sock`), not the release folder
123
+ path (`/srv/projet/releases/1234/tmp/puma.sock`).
124
+
125
+ Puma will detect the release path socket as different than the one provided by
126
+ systemd and attempt to bind it again, resulting in the exception `There is
127
+ already a server bound to:`.
128
+
129
+ ### Binding
130
+
131
+ By default, you need to configure Puma to have binds matching with all
132
+ ListenStream statements. Any mismatched systemd ListenStreams will be closed by
133
+ Puma.
134
+
135
+ To automatically bind to all activated sockets, the option
136
+ `--bind-to-activated-sockets` can be used. This matches the config DSL
137
+ `bind_to_activated_sockets` statement. This will cause Puma to create a bind
138
+ automatically for any activated socket. When systemd socket activation is not
139
+ enabled, this option does nothing.
140
+
141
+ This also accepts an optional argument `only` (DSL: `'only'`) to discard any
142
+ binds that's not socket activated.
143
+
144
+ ## Usage
145
+
146
+ Without socket activation, use `systemctl` as root (i.e., via `sudo`) as with
147
+ other system services:
148
+
149
+ ~~~~ sh
150
+ # After installing or making changes to puma.service
151
+ systemctl daemon-reload
152
+
153
+ # Enable so it starts on boot
154
+ systemctl enable puma.service
155
+
156
+ # Initial startup.
157
+ systemctl start puma.service
158
+
159
+ # Check status
160
+ systemctl status puma.service
161
+
162
+ # A normal restart. Warning: listener's sockets will be closed
163
+ # while a new puma process initializes.
164
+ systemctl restart puma.service
165
+ ~~~~
166
+
167
+ With socket activation, several but not all of these commands should be run for
168
+ both socket and service:
169
+
170
+ ~~~~ sh
171
+ # After installing or making changes to either puma.socket or
172
+ # puma.service.
173
+ systemctl daemon-reload
174
+
175
+ # Enable both socket and service, so they start on boot. Alternatively
176
+ # you could leave puma.service disabled, and systemd will start it on
177
+ # the first use (with startup lag on the first request)
178
+ systemctl enable puma.socket puma.service
179
+
180
+ # Initial startup. The Requires directive (see above) ensures the
181
+ # socket is started before the service.
182
+ systemctl start puma.socket puma.service
183
+
184
+ # Check the status of both socket and service.
185
+ systemctl status puma.socket puma.service
186
+
187
+ # A "hot" restart, with systemd keeping puma.socket listening and
188
+ # providing to the new puma (master) instance.
189
+ systemctl restart puma.service
190
+
191
+ # A normal restart, needed to handle changes to
192
+ # puma.socket, such as changing the ListenStream ports. Note
193
+ # daemon-reload (above) should be run first.
194
+ systemctl restart puma.socket puma.service
195
+ ~~~~
196
+
197
+ Here is sample output from `systemctl status` with both service and socket
198
+ running:
199
+
200
+ ~~~~
201
+ ● puma.socket - Puma HTTP Server Accept Sockets
202
+ Loaded: loaded (/etc/systemd/system/puma.socket; enabled; vendor preset: enabled)
203
+ Active: active (running) since Thu 2016-04-07 08:40:19 PDT; 1h 2min ago
204
+ Listen: 0.0.0.0:9233 (Stream)
205
+ 0.0.0.0:9234 (Stream)
206
+
207
+ Apr 07 08:40:19 hx systemd[874]: Listening on Puma HTTP Server Accept Sockets.
208
+
209
+ ● puma.service - Puma HTTP Server
210
+ Loaded: loaded (/etc/systemd/system/puma.service; enabled; vendor preset: enabled)
211
+ Active: active (running) since Thu 2016-04-07 08:40:19 PDT; 1h 2min ago
212
+ Main PID: 28320 (ruby)
213
+ CGroup: /system.slice/puma.service
214
+ ├─28320 puma 3.3.0 (tcp://0.0.0.0:9233,ssl://0.0.0.0:9234?key=key.pem&cert=cert.pem) [app]
215
+ ├─28323 puma: cluster worker 0: 28320 [app]
216
+ └─28327 puma: cluster worker 1: 28320 [app]
217
+
218
+ Apr 07 08:40:19 hx puma[28320]: Puma starting in cluster mode...
219
+ Apr 07 08:40:19 hx puma[28320]: * Version 3.3.0 (ruby 2.2.4-p230), codename: Jovial Platypus
220
+ Apr 07 08:40:19 hx puma[28320]: * Min threads: 0, max threads: 16
221
+ Apr 07 08:40:19 hx puma[28320]: * Environment: production
222
+ Apr 07 08:40:19 hx puma[28320]: * Process workers: 2
223
+ Apr 07 08:40:19 hx puma[28320]: * Phased restart available
224
+ Apr 07 08:40:19 hx puma[28320]: * Activated tcp://0.0.0.0:9233
225
+ Apr 07 08:40:19 hx puma[28320]: * Activated ssl://0.0.0.0:9234?key=key.pem&cert=cert.pem
226
+ Apr 07 08:40:19 hx puma[28320]: Use Ctrl-C to stop
227
+ ~~~~
228
+
229
+ ### capistrano3-puma
230
+
231
+ By default, [capistrano3-puma](https://github.com/seuros/capistrano-puma) uses
232
+ `pumactl` for deployment restarts outside of systemd. To learn the exact
233
+ commands that this tool would use for `ExecStart` and `ExecStop`, use the
234
+ following `cap` commands in dry-run mode, and update from the above forking
235
+ service configuration accordingly. Note also that the configured `User` should
236
+ likely be the same as the capistrano3-puma `:puma_user` option.
237
+
238
+ ~~~~ sh
239
+ stage=production # or different stage, as needed
240
+ cap $stage puma:start --dry-run
241
+ cap $stage puma:stop --dry-run
242
+ ~~~~
243
+
244
+ ### Disabling Puma Systemd Integration
245
+
246
+ If you would like to disable Puma's systemd integration, for example if you handle it elsewhere
247
+ in your code yourself, simply set the the environment variable `PUMA_SKIP_SYSTEMD` to any value.
248
+
249
+
250
+
251
+ [Restart]: https://www.freedesktop.org/software/systemd/man/systemd.service.html#Restart=
252
+ [#1367]: https://github.com/puma/puma/issues/1367
253
+ [#1499]: https://github.com/puma/puma/issues/1499