-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_server.py
49 lines (41 loc) · 1.7 KB
/
run_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import subprocess
import time
import sys
import os
import argparse
session_start = time.strftime("%d%m%Y%H%M%S")
CRASH_log_file = f"crashes/crashes_{session_start}.log"
INTERPRETER_log_file = "logs/Interpreter.log"
def log_crash():
os.makedirs("crashes", exist_ok=True)
with open(CRASH_log_file, "a") as f:
with open(INTERPRETER_log_file, "r") as i:
f.write(i.readlines()[-1].lstrip("[*] "))
print(f"Crash logged to {CRASH_log_file}")
return
def run_server(server_path, library_path, replay_mode=False):
env = os.environ.copy()
env['LD_PRELOAD'] = library_path
while True:
try:
process = subprocess.Popen([server_path], env=env)
process.wait()
if process.poll() != 0:
print(f"Server crashed. Restarting in 2 seconds.")
print("========================================\n")
if not replay_mode:
log_crash()
time.sleep(2)
except KeyboardInterrupt:
print("Script interrupted by user. Exiting...")
sys.exit(0)
except Exception as e:
print(f"An unexpected error occurred: {e}")
time.sleep(2)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Run a server process with a preloaded library.")
parser.add_argument("--server", required=True, help="Path to the server executable.")
parser.add_argument("--library", required=True, help="Path to the library.")
parser.add_argument("-r", "--replay", action="store_true", help="Run in replay mode (skip crash logging)")
args = parser.parse_args()
run_server(args.server, args.library, args.replay)