Send SIGKILL to rsyslog if hard cancellation is needed

This commit is contained in:
Hao Liu 2023-12-12 11:55:00 -05:00 committed by Hao Liu
parent b5f6aac3aa
commit 6440e3cb55

View File

@ -11,10 +11,12 @@ def write_stdout(s):
sys.stdout.write(s)
sys.stdout.flush()
def write_stderr(s):
sys.stderr.write(s)
sys.stderr.write(f"[rsyslog-4xx-recovery] {s}")
sys.stderr.flush()
def main():
while 1:
write_stdout("READY\n")
@ -47,6 +49,15 @@ def main():
except Exception as e:
write_stderr(str(e))
if "action-0-omhttp queue: need to do hard cancellation" in log_message:
try:
write_stderr(
f"{datetime.datetime.now(timezone.utc)} - sending SIGKILL to proc=[{proc_details['processname']}] with pid=[{int(proc_details['pid'])}] due to log_message=[{log_message}]\n"
)
os.kill(int(proc_details["pid"]), signal.SIGKILL)
except Exception as e:
write_stderr(str(e))
write_stdout("RESULT 2\nOK")