1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00
puma--puma/docs/plugins.md

39 lines
1.5 KiB
Markdown
Raw Normal View History

2017-08-17 11:42:00 -04:00
## Plugins
Puma 3.0 added support for plugins that can augment configuration and service
operations.
2017-08-17 11:42:00 -04:00
There are two canonical plugins to aid in the development of new plugins:
2017-08-17 11:42:00 -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):
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
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
Plugins are activated based on path requirements so, activating the `heroku`
plugin is much like `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 comes with Puma, so it is always available.
2017-08-17 11:42:00 -04:00
To use the `heroku` plugin, add `puma-heroku` to your Gemfile or install it.
### API
## Server-wide hooks
2017-08-17 11:42:00 -04:00
Plugins can use a couple of hooks at the server level: `start` and `config`.
2017-08-17 11:42:00 -04:00
`start` runs when the server has started and allows the plugin to initiate other
functionality to augment Puma.
2017-08-17 11:42:00 -04:00
`config` runs when the server is being configured and receives a `Puma::DSL`
object that is useful for additional configuration.
2017-08-17 11:42:00 -04:00
Public methods in [`Puma::Plugin`](../lib/puma/plugin.rb) are treated as a
public API for plugins.