core: more liberally release port leases
This commit is contained in:
parent
5eb1dfbddd
commit
84f889e801
|
@ -32,6 +32,7 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
|
@leased = []
|
||||||
@machine = env[:machine]
|
@machine = env[:machine]
|
||||||
|
|
||||||
# Acquire a process-level lock so that we don't choose a port
|
# Acquire a process-level lock so that we don't choose a port
|
||||||
|
@ -46,6 +47,13 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
|
|
||||||
|
# Always run the recover method so that we release leases
|
||||||
|
recover(env)
|
||||||
|
end
|
||||||
|
|
||||||
|
def recover(env)
|
||||||
|
lease_release
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
@ -176,10 +184,22 @@ module Vagrant
|
||||||
f.write(Time.now.to_i.to_s + "\n")
|
f.write(Time.now.to_i.to_s + "\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Add to the leased array so we unlease it right away
|
||||||
|
@leased << port.to_s
|
||||||
|
|
||||||
# Things look good to us!
|
# Things look good to us!
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def lease_release
|
||||||
|
leasedir = @machine.env.data_dir.join("fp-leases")
|
||||||
|
|
||||||
|
@leased.each do |port|
|
||||||
|
path = leasedir.join(port)
|
||||||
|
path.delete if path.file?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def port_check(port)
|
def port_check(port)
|
||||||
is_port_open?("127.0.0.1", port)
|
is_port_open?("127.0.0.1", port)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue