scripts: Add argparse option to `restart-zerver` for `--fill-cache`.

Nowm unless you specify `--fill-cache`, memcached caches will not be
pre-filled after a server restart. This will be helpful when someone
is in a hurry (e.g. if the server is down right now, or if he/she
testing a configuration change in a newly setup server), it's best to
just restart without pre-filling the cache.

Fixes: #10900.
This commit is contained in:
Harshit Bansal 2019-01-14 16:30:53 +00:00 committed by Tim Abbott
parent 46f4e58782
commit 50ef91bb08
3 changed files with 11 additions and 4 deletions

View File

@ -4,4 +4,4 @@ USER=zulip
# Cron job to restart the Zulip server weekly, with the goal of # Cron job to restart the Zulip server weekly, with the goal of
# minimizing the impact of any memory leaks that we might grow. # minimizing the impact of any memory leaks that we might grow.
0 6 * * 7 zulip /home/zulip/deployments/current/scripts/restart-server 0 6 * * 7 zulip /home/zulip/deployments/current/scripts/restart-server --fill-cache

View File

@ -177,7 +177,7 @@ if migrations_needed:
subprocess.check_call(["./manage.py", "create_realm_internal_bots"], preexec_fn=su_to_zulip) subprocess.check_call(["./manage.py", "create_realm_internal_bots"], preexec_fn=su_to_zulip)
logging.info("Restarting Zulip...") logging.info("Restarting Zulip...")
subprocess.check_output(["./scripts/restart-server"], preexec_fn=su_to_zulip) subprocess.check_output(["./scripts/restart-server", "--fill-cache"], preexec_fn=su_to_zulip)
logging.info("Upgrade complete!") logging.info("Upgrade complete!")
if not args.skip_purge_old_deployments: if not args.skip_purge_old_deployments:

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import argparse
import configparser import configparser
import os import os
import sys import sys
@ -14,6 +15,11 @@ logging.Formatter.converter = time.gmtime
logging.basicConfig(format="%(asctime)s restart-server: %(message)s", logging.basicConfig(format="%(asctime)s restart-server: %(message)s",
level=logging.INFO) level=logging.INFO)
parser = argparse.ArgumentParser()
parser.add_argument('--fill-cache', action='store_true', dest='fill_cache', default=False,
help='Fill the memcached caches')
args = parser.parse_args()
deploy_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..')) deploy_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..'))
os.chdir(deploy_path) os.chdir(deploy_path)
@ -24,8 +30,9 @@ if pwd.getpwuid(os.getuid()).pw_name != "zulip":
# Send a statsd event on restarting the server # Send a statsd event on restarting the server
subprocess.check_call(["./manage.py", "send_stats", "incr", "events.server_restart", str(int(time.time()))]) subprocess.check_call(["./manage.py", "send_stats", "incr", "events.server_restart", str(int(time.time()))])
logging.info("Filling memcached caches") if args.fill_cache:
subprocess.check_call(["./manage.py", "fill_memcached_caches"]) logging.info("Filling memcached caches")
subprocess.check_call(["./manage.py", "fill_memcached_caches"])
core_server_services = ["zulip-django", "zulip-senders:*"] core_server_services = ["zulip-django", "zulip-senders:*"]
if os.path.exists("/etc/supervisor/conf.d/thumbor.conf"): if os.path.exists("/etc/supervisor/conf.d/thumbor.conf"):