I have a server that starts cowboy and ranch as an independent application — that is, they have their own supervisor, they are not in the supervisor tree of my application.
Is it best practice to include cowboy into the application's supervisor tree? If so, how do you do it?
The typical way to use Cowboy, as described in the "Getting Started" documentation is to list it as a dependency in your .app
file. Doing this will inform the runtime that the Cowboy application needs to be started before your own application can start.
This setup is easy (one line in your .app
) and should generally be robust. Cowboy will restart crashed workers as needed, and your application doesn't really worry about it. Lots of other vital libraries (e.g. the kernel) are started this same way, so you're in good company.
However, it's possible that your application has some need to deeply entwine itself with Cowboy. Maybe you expect the entire Cowboy supervision tree to crash and you want to restart it? Or maybe you need to restart Cowboy when some process of yours dies?
For this, you'll want to look at cowboy_sup:start_link/0
and ranch_sup:start_link/0
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With