Restricting the port range used by matlab-proxy?

We are trying the MATLAB-proxy app and have setup a virtual environment with the project code from https://github.com/mathworks/matlab-proxy and are using this configuration for our OOD application (GitHub - wright-cemrc-projects/uwmadison_matlab_proxy_app: MATLAB OnDemand application that runs via an http server) that will source the virtual environment and launch the app.

The matlab-proxy-app creates a web server that OOD app can redirect to.

Now, we are wondering if we can set this up to work within a limited port range? Is there a way on the OOD side to limit to a port range and provide this over to the matlab-proxy-app as the port to launch with? This might allow for a limited firewall rule to support matlab-proxy.

The find_port used by many most apps

port=$(find_port ${host})

really is just a convenience method defined by OOD to find an available, open, port number. You could do whatever you want here, defining a custom thing if you want as long as it produces an appropriate port number, but this function is really good as it checks if the port is in used, and will pick another if so.
Better yet, it already supports exactly what you ask for via optional argument 2 and 3:

port=$(find_port ${host} 6000 6010)

if you wish to have it limited to a just a few ports.

Documentation here:

edit: oh i just now noticed that the min_port and max_port default values can also be directly configured in the batch_connect yml

so i guess just do that instead of fiddling with the scripts.

Thanks @Micket! Yes the second link @Micket provides shows that you can even set the port range with min_port and max_port.

Thank you @Micket for this nice solution.

Within the matlab-proxy OOD application, in the template/before.sh.erb we now are using:

# Restrict the port range
port=$(find_port ${host} 5000 6000)

export MWI_AUTH_TOKEN=$(create_passwd 32)
password=$MWI_AUTH_TOKEN
export MWI_BASE_URL="/node/$host/$port/"
export MWI_APP_PORT=$port

And can see the process log showing it starting in a port in that 5000-6000 range.