2016-04-07 15:03:22 +02:00
|
|
|
#!/usr/bin/env python
|
2013-08-23 20:49:06 +02:00
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
import base64
|
|
|
|
|
|
|
|
short_user = sys.argv[1]
|
|
|
|
api_key = sys.argv[2]
|
|
|
|
ccache_data_encoded = sys.argv[3]
|
|
|
|
|
|
|
|
# Update the Kerberos ticket cache file
|
|
|
|
program_name = "zmirror-%s" % (short_user,)
|
2015-10-14 22:31:08 +02:00
|
|
|
with open("/home/zulip/ccache/%s" % (program_name,), "w") as f:
|
2013-08-23 20:49:06 +02:00
|
|
|
f.write(base64.b64decode(ccache_data_encoded))
|
|
|
|
|
|
|
|
# Setup API key
|
2013-10-04 19:19:57 +02:00
|
|
|
api_key_path = "/home/zulip/api-keys/%s" % (program_name,)
|
2016-03-10 18:18:37 +01:00
|
|
|
open(api_key_path, "w").write(api_key + "\n")
|
2013-08-23 20:49:06 +02:00
|
|
|
|
|
|
|
# Setup supervisord configuration
|
|
|
|
supervisor_path = "/etc/supervisor/conf.d/%s.conf" % (program_name,)
|
2013-10-04 19:19:57 +02:00
|
|
|
template = "/home/zulip/zulip/bots/zmirror_private.conf.template"
|
2016-03-10 18:18:37 +01:00
|
|
|
template_data = open(template).read()
|
2013-10-04 19:19:57 +02:00
|
|
|
session_path = "/home/zulip/zephyr_sessions/%s" % (program_name,)
|
2013-10-01 19:45:29 +02:00
|
|
|
|
|
|
|
# Preserve mail zephyrs forwarding setting across rewriting the config file
|
|
|
|
|
|
|
|
try:
|
2016-03-10 18:18:37 +01:00
|
|
|
if "--forward-mail-zephyrs" in open(supervisor_path, "r").read():
|
2013-10-01 19:45:29 +02:00
|
|
|
template_data = template_data.replace("--use-sessions", "--use-sessions --forward-mail-zephyrs")
|
|
|
|
except Exception:
|
|
|
|
pass
|
2016-03-10 18:18:37 +01:00
|
|
|
open(supervisor_path, "w").write(template_data.replace("USERNAME", short_user))
|
2013-08-23 20:49:06 +02:00
|
|
|
|
|
|
|
# Delete your session
|
|
|
|
subprocess.check_call(["rm", "-f", session_path])
|
|
|
|
# Update your supervisor config, which may restart your mirror
|
|
|
|
subprocess.check_call(["supervisorctl", "reread"])
|
|
|
|
subprocess.check_call(["supervisorctl", "update"])
|
|
|
|
# Restart your mirror, in case it wasn't restarted by the previous
|
|
|
|
# (Otherwise if the mirror lost subs, this would do nothing)
|
|
|
|
# TODO: check whether we JUST restarted it first
|
|
|
|
subprocess.check_call(["supervisorctl", "restart", program_name])
|