2020-04-02 09:59:28 -04:00
|
|
|
#!/usr/bin/env python3
|
2014-01-22 10:46:25 -05:00
|
|
|
|
2014-03-17 13:17:20 -04:00
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
import os
|
|
|
|
import traceback
|
|
|
|
import signal
|
2016-07-29 22:55:52 -04:00
|
|
|
from types import FrameType
|
2014-03-17 13:17:20 -04:00
|
|
|
from zulip import RandomExponentialBackoff
|
2014-02-28 14:00:03 -05:00
|
|
|
|
2020-04-18 18:59:12 -04:00
|
|
|
def die(signal: int, frame: FrameType) -> None:
|
2016-07-29 22:55:52 -04:00
|
|
|
"""We actually want to exit, so run os._exit (so as not to be caught and restarted)"""
|
2014-03-17 13:17:20 -04:00
|
|
|
os._exit(1)
|
2014-02-28 14:00:03 -05:00
|
|
|
|
2014-03-17 13:17:20 -04:00
|
|
|
signal.signal(signal.SIGINT, die)
|
2014-02-28 12:51:07 -05:00
|
|
|
|
2014-03-17 13:17:20 -04:00
|
|
|
args = [os.path.join(os.path.dirname(sys.argv[0]), "jabber_mirror_backend.py")]
|
|
|
|
args.extend(sys.argv[1:])
|
2014-03-02 00:49:46 -05:00
|
|
|
|
2014-03-17 13:30:44 -04:00
|
|
|
backoff = RandomExponentialBackoff(timeout_success_equivalent=300)
|
2014-03-17 13:17:20 -04:00
|
|
|
while backoff.keep_going():
|
2015-11-01 11:11:06 -05:00
|
|
|
print("Starting Jabber mirroring bot")
|
2014-03-02 00:49:46 -05:00
|
|
|
try:
|
2014-03-17 13:17:20 -04:00
|
|
|
ret = subprocess.call(args)
|
2017-01-08 10:46:33 -05:00
|
|
|
except Exception:
|
2014-03-17 13:17:20 -04:00
|
|
|
traceback.print_exc()
|
2014-03-17 13:18:23 -04:00
|
|
|
else:
|
|
|
|
if ret == 2:
|
|
|
|
# Don't try again on initial configuration errors
|
|
|
|
sys.exit(ret)
|
|
|
|
|
2014-03-17 13:17:20 -04:00
|
|
|
backoff.fail()
|
|
|
|
|
2015-11-01 11:11:06 -05:00
|
|
|
print("")
|
|
|
|
print("")
|
|
|
|
print("ERROR: The Jabber mirroring bot is unable to continue mirroring Jabber.")
|
|
|
|
print("Please contact zulip-devel@googlegroups.com if you need assistance.")
|
|
|
|
print("")
|
2014-03-17 13:17:20 -04:00
|
|
|
sys.exit(1)
|