@@ -21,7 +21,7 @@ def run_server_script(args):
2121 # Define a wrapper function to pass the arguments to the main function
2222 def server_main ():
2323 import sys
24- sys .argv = ['server.py' , '--rpc-port' , str (args .rpc_port ), '--log-dir' , log_dir ]
24+ sys .argv = ['server.py' , '--rpc-port' , str (args .rpc_port ), '--log-dir' , log_dir , '--disable-log-file' if args . disable_log_file else '' ]
2525 main ()
2626
2727 # Start the main function as a new process
@@ -32,7 +32,10 @@ def server_main():
3232def run_start_script (args ):
3333 # Start the start.sh script in its own directory as a new process group
3434 process = subprocess .Popen (
35- ['bash' , 'start-agent.sh' if not args .debug else 'start-debug.sh' , '-t' , args .team_name , '--rpc-port' , args .rpc_port , '--rpc-type' , 'grpc' , '-p' , args .server_port ,
35+ ['bash' , 'start-agent.sh' if not args .debug else 'start-debug.sh' ,
36+ '-t' , args .team_name ,
37+ '--rpc-port' , args .rpc_port , '--rpc-type' , 'grpc' ,
38+ '-p' , args .server_port , '-h' , args .server_host ,
3639 '--coach' if args .coach else '--goalie' if args .goalie else '--player' ],
3740 cwd = 'scripts/proxy' , # Corrected directory to where start.sh is located
3841 preexec_fn = os .setsid , # Create a new session and set the process group ID
@@ -44,16 +47,19 @@ def run_start_script(args):
4447stop_thread = threading .Event ()
4548
4649
47- def stream_output_to_file (process , name ):
50+ def stream_output_to_file (process , name , args ):
4851 # Stream output from the process and log it to a file with the given name
49- with open (f"{ log_dir } /{ name } .log" , "a" ) as f :
50- while not stop_thread .is_set ():
51- output = process .stdout .readline ()
52- if output :
52+ f = None if args .disable_log_file else open (f"{ log_dir } /{ name } .log" , "a" )
53+ while not stop_thread .is_set ():
54+ output = process .stdout .readline ()
55+ if output :
56+ if f :
5357 f .write (output .decode ())
5458 f .flush ()
5559 else :
56- break
60+ print (output .decode ())
61+ else :
62+ break
5763 process .stdout .close ()
5864
5965def kill_process_group (process ):
@@ -79,10 +85,12 @@ def kill_rpc_server_process(process):
7985 parser .add_argument ('-d' , '--debug' , required = False , help = 'Enable debug mode' , default = False , action = 'store_true' )
8086 parser .add_argument ('--use-random-port' , required = False , help = 'Use a random port for the server' , default = False , action = 'store_true' )
8187 parser .add_argument ('--use-random-name' , required = False , help = 'Use a random team name' , default = False , action = 'store_true' )
88+ parser .add_argument ('--server-host' , required = False , help = 'The host of the server' , default = 'localhost' )
8289 parser .add_argument ('--server-port' , required = False , help = 'The port of the server' , default = '6000' )
8390 parser .add_argument ('--close-server' , required = False , help = 'Close the server' , default = False , action = 'store_true' )
8491 parser .add_argument ('--coach' , required = False , help = 'Use coach instead of proxy' , default = False , action = 'store_true' )
8592 parser .add_argument ('--goalie' , required = False , help = 'Use goalie instead of proxy' , default = False , action = 'store_true' )
93+ parser .add_argument ('--disable-log-file' , required = False , help = 'Disable logging to a file' , default = False , action = 'store_true' )
8694 parser .add_argument ('--log-dir' , required = False , help = 'The directory to store logs' , default = None )
8795 args = parser .parse_args ()
8896
@@ -91,7 +99,8 @@ def kill_rpc_server_process(process):
9199 log_dir = os .path .join (os .getcwd (), 'logs' , f"{ datetime .datetime .now ().strftime ('%Y-%m-%d_%H-%M-%S' )} _{ random .randint (100000 , 999999 )} " )
92100 else :
93101 log_dir = args .log_dir
94- start_team_logger = setup_logger ('start-team' , log_dir , console_level = logging .DEBUG , file_level = logging .DEBUG , console_format_str = '%(message)s' )
102+ start_team_logger = setup_logger ('start-team' , log_dir , console_level = logging .DEBUG , file_level = logging .DEBUG if not args .disable_log_file else None ,
103+ console_format_str = '%(message)s' )
95104
96105 start_team_logger .debug (f"Arguments: { args = } " )
97106
@@ -119,7 +128,7 @@ def kill_rpc_server_process(process):
119128 # Monitor both processes and log their outputs
120129 start_team_logger .debug ("Monitoring processes..." )
121130
122- start_thread = threading .Thread (target = stream_output_to_file , args = (start_process , 'proxy' ))
131+ start_thread = threading .Thread (target = stream_output_to_file , args = (start_process , 'proxy' , args ))
123132 start_thread .start ()
124133
125134 def signal_handler (sig , frame ):
0 commit comments