26 lines
729 B
Python
26 lines
729 B
Python
#!/usr/bin/env python3
|
|
"""Wrapper for xmpp_agent_core.py --agent xiaoguo"""
|
|
import sys, os, signal
|
|
|
|
PID_FILE = "/tmp/xmpp_xiaoguo_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_xiaoguo_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', 'xiaoguo']
|
|
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)
|