Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ElasticManager constructor auto IP config #190

Merged
merged 2 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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