mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-01-01 12:41:43 +08:00
disconnect node from remote machine (#915)
* disconnect node from remote machine * return ok if disconnect is successful * formatting * Update lib/livebook/runtime/attached.ex * move disconnection of node to NodeManager * add doc about parent node option * Update lib/livebook/runtime/erl_dist/node_manager.ex Co-authored-by: José Valim <jose.valim@gmail.com> Co-authored-by: Jonatan Kłosko <jonatanklosko@gmail.com>
This commit is contained in:
parent
5579258722
commit
1b7b3080e1
2 changed files with 14 additions and 2 deletions
|
@ -28,7 +28,8 @@ defmodule Livebook.Runtime.Attached do
|
|||
|
||||
case Node.ping(node) do
|
||||
:pong ->
|
||||
server_pid = Livebook.Runtime.ErlDist.initialize(node)
|
||||
opts = [parent_node: node()]
|
||||
server_pid = Livebook.Runtime.ErlDist.initialize(node, opts)
|
||||
{:ok, %__MODULE__{node: node, cookie: cookie, server_pid: server_pid}}
|
||||
|
||||
:pang ->
|
||||
|
|
|
@ -37,6 +37,11 @@ defmodule Livebook.Runtime.ErlDist.NodeManager do
|
|||
|
||||
* `:auto_termination` - whether to terminate the manager
|
||||
when the last runtime server terminates. Defaults to `true`.
|
||||
|
||||
* `:parent_node` - indicates which node spawned the node manager.
|
||||
It is used to disconnect the node when the server terminates,
|
||||
which happens when the last session using the node disconnects.
|
||||
Defaults to `nil`
|
||||
"""
|
||||
def start(opts \\ []) do
|
||||
{opts, gen_opts} = split_opts(opts)
|
||||
|
@ -78,6 +83,7 @@ defmodule Livebook.Runtime.ErlDist.NodeManager do
|
|||
def init(opts) do
|
||||
unload_modules_on_termination = Keyword.get(opts, :unload_modules_on_termination, true)
|
||||
auto_termination = Keyword.get(opts, :auto_termination, true)
|
||||
parent_node = Keyword.get(opts, :parent_node)
|
||||
|
||||
## Initialize the node
|
||||
|
||||
|
@ -105,7 +111,8 @@ defmodule Livebook.Runtime.ErlDist.NodeManager do
|
|||
server_supevisor: server_supevisor,
|
||||
runtime_servers: [],
|
||||
initial_ignore_module_conflict: initial_ignore_module_conflict,
|
||||
original_standard_error: original_standard_error
|
||||
original_standard_error: original_standard_error,
|
||||
parent_node: parent_node
|
||||
}}
|
||||
end
|
||||
|
||||
|
@ -122,6 +129,10 @@ defmodule Livebook.Runtime.ErlDist.NodeManager do
|
|||
ErlDist.unload_required_modules()
|
||||
end
|
||||
|
||||
if state.parent_node do
|
||||
Node.disconnect(state.parent_node)
|
||||
end
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue