Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it recommended to add cowboy to the application supervisor tree?

Tags:

erlang

cowboy

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?

like image 476
zztczcx Avatar asked Feb 02 '15 06:02

zztczcx


1 Answers

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.

like image 122
Nathaniel Waisbrot Avatar answered Nov 01 '22 20:11

Nathaniel Waisbrot