Hello community
I have a number of ssh server processes that I start using Erlang’s daemon/2 function http://erlang.org/doc/man/ssh.html#daemon-2
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.