Manage sshd supervisors


Hello community :slight_smile:

I have a number of ssh server processes that I start using Erlang’s daemon/2 function

Starting such a daemon adds it to the supervision tree of the ssh app which is fine by me, there is a parent sup ssh_sup, supervisor for daemon supervisors sshd_sup and then a supervisor for each port that handles acceptor and connections (is registered with port number).

Now from time to time I need to stop these or possibly restart them on other ports. At the moment the only way I can do that is this: Supervisor.stop(:"ssh_system_0.0.0.0_65535_default_sup"). It works, but obviously the port numer is dynamic so I must generate atoms (no biggie since they’d always exist) and also I feel that I rely on internal naming which might break at some point.

Is there a “cleaner” way to handle that? Or is it fine as it is?

I can think of setting up a dynamic supervisor and supervise each of these supervisors in my app (put them into a registry or something), then I’d be able to kill them just like I do with any other process, but it kinda seems like an overkill? Also I don’t quite like such a cross-app supervision.

Other alternative would be to put the pids that daemon/2 returns (per port supervisor pid’s) in a registry directly, but I don’t want to save pids since theoretically they can be restarted.

Appreciate your feedback.



Answering my own question in case someone stumbles upon it - yes there is a cleaner way and it’s pretty obvios - does exaclty that. I explicitly pass host for consistency so the start uses daemon/3 now. There’s also stop_listener/1/2/3 that spares connections.

I actually knew about these functions at the beginning but then went deep into the code and couldn’t see the forest for the trees :smiley: