2017-08-17 11:42:00 -04:00
|
|
|
## Plugins
|
|
|
|
|
2019-10-02 06:42:46 -04:00
|
|
|
Puma 3.0 added support for plugins that can augment configuration and service
|
|
|
|
operations.
|
2017-08-17 11:42:00 -04:00
|
|
|
|
|
|
|
2 canonical plugins to look to aid in development of further plugins:
|
|
|
|
|
2019-10-02 06:42:46 -04:00
|
|
|
* [tmp\_restart](https://github.com/puma/puma/blob/master/lib/puma/plugin/tmp_restart.rb):
|
|
|
|
Restarts the server if the file `tmp/restart.txt` is touched
|
|
|
|
* [heroku](https://github.com/puma/puma-heroku/blob/master/lib/puma/plugin/heroku.rb):
|
2020-12-09 09:52:43 -05:00
|
|
|
Packages up the default configuration used by puma on Heroku (being sunset with the release of Puma 5.0)
|
2017-08-17 11:42:00 -04:00
|
|
|
|
2019-10-02 06:42:46 -04:00
|
|
|
Plugins are activated in a puma configuration file (such as `config/puma.rb'`)
|
|
|
|
by adding `plugin "name"`, such as `plugin "heroku"`.
|
2017-08-17 11:42:00 -04:00
|
|
|
|
2019-10-02 06:42:46 -04:00
|
|
|
Plugins are activated based simply on path requirements so, activating the
|
|
|
|
`heroku` plugin will simply be doing `require "puma/plugin/heroku"`. This
|
|
|
|
allows gems to provide multiple plugins (as well as unrelated gems to provide
|
|
|
|
puma plugins).
|
2017-08-17 11:42:00 -04:00
|
|
|
|
|
|
|
The `tmp_restart` plugin is bundled with puma, so it can always be used.
|
|
|
|
|
|
|
|
To use the `heroku` plugin, add `puma-heroku` to your Gemfile or install it.
|
|
|
|
|
|
|
|
### API
|
|
|
|
|
2019-10-02 06:42:46 -04:00
|
|
|
## Server-wide hooks
|
2017-08-17 11:42:00 -04:00
|
|
|
|
2019-10-02 06:42:46 -04:00
|
|
|
Plugins can use a couple of hooks at server level: `start` and `config`.
|
2017-08-17 11:42:00 -04:00
|
|
|
|
2019-10-02 06:42:46 -04:00
|
|
|
`start` runs when the server has started and allows the plugin to start other
|
|
|
|
functionality to augment puma.
|
2017-08-17 11:42:00 -04:00
|
|
|
|
2019-10-02 06:42:46 -04:00
|
|
|
`config` runs when the server is being configured and is passed a `Puma::DSL`
|
|
|
|
object that can be used to add additional configuration.
|
2017-08-17 11:42:00 -04:00
|
|
|
|
2021-05-04 14:33:06 -04:00
|
|
|
Any public methods in [`Puma::Plugin`](../lib/puma/plugin.rb) are the public API that any plugin may
|
2019-10-02 06:42:46 -04:00
|
|
|
use.
|