Skip to content

Commit

Permalink
Update ElasticManager constructor auto IP config (#190)
Browse files Browse the repository at this point in the history
* Update Elastic auto IP config

* Update ElasticManager auto IP platforms
  • Loading branch information
mikeingold authored Jun 30, 2023
1 parent a4a8cd4 commit c665258
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"

[compat]
julia = "1"
julia = "1.2"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ ElasticManager(addr, port) = ElasticManager(;addr=addr, port=port)
ElasticManager(addr, port, cookie) = ElasticManager(;addr=addr, port=port, cookie=cookie)
```

On Linux and Mac, you can set `addr=:auto` to automatically use the host's private IP address on the local network, which will allow other workers on this network to connect. You can also use `port=0` to let the OS choose a random free port for you (some systems may not support this). Once created, printing the `ElasticManager` object prints the command which you can run on workers to connect them to the master, e.g.:
You can set `addr=:auto` to automatically use the host's private IP address on the local network, which will allow other workers on this network to connect. You can also use `port=0` to let the OS choose a random free port for you (some systems may not support this). Once created, printing the `ElasticManager` object prints the command which you can run on workers to connect them to the master, e.g.:

```julia
julia> em = ElasticManager(addr=:auto, port=0)
Expand Down
26 changes: 6 additions & 20 deletions src/elastic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ struct ElasticManager <: ClusterManager
Distributed.init_multi()
cookie !== nothing && cluster_cookie(cookie)

# Automatically check for the IP address of the local machine
if addr == :auto
addr = get_private_ip()
try
addr = Sockets.getipaddr(IPv4)
catch
error("Failed to automatically get host's IP address. Please specify `addr=` explicitly.")
end
end

l_sock = listen(addr, port)
Expand Down Expand Up @@ -134,25 +139,6 @@ function elastic_worker(cookie, addr="127.0.0.1", port=9009; stdout_to_master=tr
start_worker(c, cookie)
end


function get_private_ip()
if Sys.islinux()
cmd = `hostname --ip-address`
elseif Sys.isapple()
cmd = `ipconfig getifaddr en0`
else
error("`addr=:auto` is only supported on Linux and Mac")
end
try
return IPv4(first(split(strip(read(cmd, String)))))
catch err
error("""Failed to automatically get host's IP address (output below). Please specify `addr=` explicitly.
\$ $(repr(cmd))
$err
""")
end
end

function get_connect_cmd(em::ElasticManager; absolute_exename=true, same_project=true)

ip = string(em.sockname[1])
Expand Down

0 comments on commit c665258

Please sign in to comment.