From 50ef91bb08bb0b37078c4365c3a50cfe4bf524d6 Mon Sep 17 00:00:00 2001 From: Harshit Bansal Date: Mon, 14 Jan 2019 16:30:53 +0000 Subject: [PATCH] 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. --- puppet/zulip/files/cron.d/restart-zulip | 2 +- scripts/lib/upgrade-zulip-stage-2 | 2 +- scripts/restart-server | 11 +++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/puppet/zulip/files/cron.d/restart-zulip b/puppet/zulip/files/cron.d/restart-zulip index e435c6a1cf..08c01d5ff8 100644 --- a/puppet/zulip/files/cron.d/restart-zulip +++ b/puppet/zulip/files/cron.d/restart-zulip @@ -4,4 +4,4 @@ USER=zulip # Cron job to restart the Zulip server weekly, with the goal of # 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 diff --git a/scripts/lib/upgrade-zulip-stage-2 b/scripts/lib/upgrade-zulip-stage-2 index 200df2581d..14a78b4c36 100755 --- a/scripts/lib/upgrade-zulip-stage-2 +++ b/scripts/lib/upgrade-zulip-stage-2 @@ -177,7 +177,7 @@ if migrations_needed: subprocess.check_call(["./manage.py", "create_realm_internal_bots"], preexec_fn=su_to_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!") if not args.skip_purge_old_deployments: diff --git a/scripts/restart-server b/scripts/restart-server index e8de5199e6..16c5edbf5c 100755 --- a/scripts/restart-server +++ b/scripts/restart-server @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import argparse import configparser import os import sys @@ -14,6 +15,11 @@ logging.Formatter.converter = time.gmtime logging.basicConfig(format="%(asctime)s restart-server: %(message)s", 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__), '..')) os.chdir(deploy_path) @@ -24,8 +30,9 @@ if pwd.getpwuid(os.getuid()).pw_name != "zulip": # Send a statsd event on restarting the server subprocess.check_call(["./manage.py", "send_stats", "incr", "events.server_restart", str(int(time.time()))]) -logging.info("Filling memcached caches") -subprocess.check_call(["./manage.py", "fill_memcached_caches"]) +if args.fill_cache: + logging.info("Filling memcached caches") + subprocess.check_call(["./manage.py", "fill_memcached_caches"]) core_server_services = ["zulip-django", "zulip-senders:*"] if os.path.exists("/etc/supervisor/conf.d/thumbor.conf"):