#!/usr/bin/env python3 """Wrapper for xmpp_agent_core.py --agent zhiwei""" import sys, os, signal PID_FILE = "/tmp/xmpp_zhiwei_bot.pid" if os.path.exists(PID_FILE): with open(PID_FILE) as f: try: old_pid = int(f.read().strip()) os.kill(old_pid, 0) print(f"xmpp_zhiwei_bot already running (PID {old_pid}), exiting.") sys.exit(0) except (ValueError, ProcessLookupError): pass with open(PID_FILE, "w") as f: f.write(str(os.getpid())) sys.argv = [sys.argv[0], '--agent', 'zhiwei'] try: exec(open(os.path.join(os.path.dirname(__file__), 'xmpp_agent_core.py')).read()) finally: if os.path.exists(PID_FILE): os.remove(PID_FILE)