2
0
mirror of https://github.com/frappe/bench.git synced 2024-11-11 15:51:03 +00:00

fixed a bug in default port for a site (#300)

* fixed a bug in nginx config

i found a bug when the user of the bench is currently using a dns-multitenant setup and he has multiple sites, and then he decides to switch to multiport setup, then all the sites present on the server get assigned the same port "80" and you can't change the port of any site due to the exception "Port 80 is being used by..." 

so i fixed the bug by assigning a new port number that is not in use to every unassigned site, so afterwards the user can set his own custom port for each site without having to face this exception and failing at this task

* fixed a compile error

that's what knowing too much c-based languages doesn to you

* changed increment method

* added a better description for port conflic 

if you are using port-based multi-tenant setup, i have found that if your ports are set in the site_config.py of your sites, or you set the port manually by using set-nginx-port command, and you have a port conflict between sites, the exception message raised is not be very helpful especially if you have many sites in your setup, so i added a list of ports that are conflicted and at what sites

and the behavior of default port assignment is changed as follows:

at first, the first site created gets port number 80, and every other site will get a new sequential port number, then, if a port is set manually that was assigned automatically, the manually set port number is applied and the old site moves to a new port

but the conflict message only displays if two ports where manually (or in the site_config) assigned to a site, and the message will display the site names

* added a message displaying the current port to site setup

added a new message that displays the mappings between sites and ports if port multi-tenant setup is used

* fixed security error in browsers

some browsers prevent low numbered ports from being used, so instead of continuously assigning ports from 80 onward, we start at 80 and then jump to 8000, and then continue from there

* fixed a problem with start port

apparently setting a site at port 8000 breaks nginx, so i changed it to 8001

* changed naming scheme to snake case
This commit is contained in:
Omar Altayyan 2016-08-29 09:54:05 +03:00 committed by Rushabh Mehta
parent df600f6458
commit 317cc26c2c

View File

@ -57,7 +57,20 @@ def prepare_sites(config, bench_path):
dns_multitenant = config.get('dns_multitenant')
for site in get_sites_with_config(bench_path=bench_path):
shared_port_exception_found = False
sites_configs = get_sites_with_config(bench_path=bench_path)
# preload all preset site ports to avoid conflicts
if not dns_multitenant:
for site in sites_configs:
if site.get("port"):
if not site["port"] in ports_in_use:
ports_in_use[site["port"]] = []
ports_in_use[site["port"]].append(site["name"])
for site in sites_configs:
if dns_multitenant:
domain = site.get('domain')
@ -83,13 +96,45 @@ def prepare_sites(config, bench_path):
else:
if not site.get("port"):
site["port"] = 80
if site["port"] in ports_in_use:
raise Exception("Port {0} is being used by another site {1}".format(site["port"], ports_in_use[site["port"]]))
site["port"] = 8001
while site["port"] in ports_in_use:
site["port"] += 1
# if site["port"] in ports_in_use:
# raise Exception("Port {0} is being used by another site {1}".format(site["port"], ports_in_use[site["port"]]))
if site["port"] in ports_in_use and not site["name"] in ports_in_use[site["port"]]:
shared_port_exception_found = True
ports_in_use[site["port"]].append(site["name"])
else:
ports_in_use[site["port"]] = []
ports_in_use[site["port"]].append(site["name"])
ports_in_use[site["port"]] = site["name"]
sites["that_use_port"].append(site)
if not dns_multitenant and shared_port_exception_found:
message = "Port conflicts found:"
port_conflict_index = 0
for port_number in ports_in_use:
if len(ports_in_use[port_number]) > 1:
port_conflict_index += 1
message += "\n{0} - Port {1} is shared among sites:".format(port_conflict_index,port_number)
for site_name in ports_in_use[port_number]:
message += " {0}".format(site_name)
raise Exception(message)
if not dns_multitenant:
message = "Port configuration list:"
port_config_index = 0
for site in sites_configs:
port_config_index += 1
message += "\n\nSite {0} assigned port: {1}".format(site["name"], site["port"])
print(message)
sites['domain_map'] = domain_map
return sites