We have a server running on the remote node. Now we want to add a new feature(implemented by gen_*) without stopping the server. So I use rpc:call(Node, my_sup, start_link, []) to start the supervisor. But unfortunately I found that the supervisor are linked to my local shell instead of the remote node, and it failed immediately (the sup process was killed) after the rpc:call.
I just wonder are there any other ways to start a newly added supervisor dynamically and remotely?
Supervisors always have to be linked to something. Usually, OTP application in its start
method spawns "root supervisor" that supervises all other processes and other supervisors. It is linked to process starting the application.
If you have such a root supervisor, you can use supervisor:start_child(SupRef, ChildSpec)
. SupRef
is a reference to the "root supervisor" (it might be a Pid or a name) and ChildSpec
would be the supervisor, you want to spawn or the gen_server itself. This function is documented here:
http://www.erlang.org/doc/man/supervisor.html#start_child-2
If you don't have a supervision tree. You can package new feature as an OTP application, which spawns the first supervisor on start.