8 """Script to set the value of the Connectivity Service port in the specified Session of the specified
9 OKS database file. If the new port is not specified, it is set to a random available port number."""
11 if session_name ==
"":
12 print(f
"Error: the session name needs to be specified")
16 session = db.get_dal(
"Session", session_name)
18 print(f
"Error could not find Session {session_name} in file {oksfile}")
22 "schema/confmodel/dunedaq.schema.xml"
28 with socket.socket()
as s:
30 s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
31 port = s.getsockname()[1]
35 new_port = find_free_port()
37 new_port = connsvc_port
39 if session.connectivity_service
is not None:
40 session.connectivity_service.service.port = new_port
41 db.update_dal(session.connectivity_service.service)
43 for app
in session.infrastructure_applications:
44 if app.className() ==
"ConnectionService":
46 for clparam
in app.commandline_parameters:
47 if "gunicorn" in clparam:
48 pattern = re.compile(
r'(.*0\.0\.0\.0)\:\d+(.*)')
49 app.commandline_parameters[index] = pattern.sub(f
'\\1:{new_port}\\2', clparam)