refactor: improve log parser termination method in DB reset
- Replaced subprocess-based termination of the log parser with a Python-native approach using os and signal modules. - Enhanced process handling to ensure proper termination of existing log parser instances before restarting. This change improves reliability and compatibility across different environments.
This commit is contained in:
@@ -116,9 +116,15 @@ def reset_db():
|
||||
db.commit()
|
||||
|
||||
# 파서 프로세스 재시작 (entrypoint.sh의 백그라운드 프로세스)
|
||||
import subprocess
|
||||
# 기존 파서 종료
|
||||
subprocess.run(["pkill", "-f", "log_parser.py"], capture_output=True)
|
||||
import subprocess, os, signal
|
||||
# 기존 파서 종료 (pkill 대신 Python-native 방식)
|
||||
for proc_dir in os.listdir("/proc") if os.path.isdir("/proc") else []:
|
||||
try:
|
||||
cmdline = open(f"/proc/{proc_dir}/cmdline", "r").read()
|
||||
if "log_parser.py" in cmdline and str(os.getpid()) != proc_dir:
|
||||
os.kill(int(proc_dir), signal.SIGTERM)
|
||||
except (ValueError, FileNotFoundError, PermissionError, ProcessLookupError):
|
||||
pass
|
||||
# 새 파서 시작
|
||||
subprocess.Popen(["python", "log_parser.py"])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user