diff --git a/scripts/lib/upgrade-zulip-stage-2 b/scripts/lib/upgrade-zulip-stage-2 index 44c2324915..38894b4da0 100755 --- a/scripts/lib/upgrade-zulip-stage-2 +++ b/scripts/lib/upgrade-zulip-stage-2 @@ -158,6 +158,18 @@ if args.ignore_static_assets: # cannot run `tools/update-prod-static`. pass elif args.from_git: + # Because `upgrade-zulip-from-git` needs to build static assets, it + # is at risk of being OOM killed on systems with limited free RAM. + mem_bytes = os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') + mem_gib = mem_bytes/(1024.**3) # e.g. 3.74 + + # Ideally, we'd have 2 thresholds here, depending on whether the + # system is running queue workers multithreaded or multiprocess. + # See puppet/zulip/manifests/app_frontend_base.pp for background. + if mem_gib < 3.8: + logging.info("Shutting down server to build static assets on a low-RAM system.") + shutdown_server() + # Note: The fact that this is before we apply puppet changes means # that we don't support adding new puppet dependencies of # update-prod-static with the git upgrade process. But it'll fail