Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
upgrade-zulip: Provide directories to run hooks before/after upgrade.
Alex Vandiver840884ec89c4
diff --git a/docs/production/deployment.md b/docs/production/deployment.mdindex 4294cecb1bb..885199b471c 100644--- a/docs/production/deployment.md+++ b/docs/production/deployment.md@@ -85,6 +85,12 @@ running on the server; though installing alongside other applicationsis not recommended, we do have [some notes on theprocess](install-existing-server.md).+## Deployment hooks++Zulip's upgrades have a hook system which allows for arbitrary+user-configured actions to run before and after an upgrade; see the+[upgrading documentation](upgrade.md#deployment-hooks) for details.+## Running Zulip's service dependencies on different machinesZulip has full support for each top-level service living on its owndiff --git a/docs/production/upgrade.md b/docs/production/upgrade.mdindex 8680794eb24..1ff44e7e15d 100644--- a/docs/production/upgrade.md+++ b/docs/production/upgrade.md@@ -211,6 +211,18 @@ earlier previous version by running`restart-server` script stops any running Zulip server, and startsthe version corresponding to the `restart-server` path you call.+## Deployment hooks++Zulip's upgrades have a hook system which allows for arbitrary+user-configured actions to run before and after an upgrade.++Files in the `/etc/zulip/pre-deploy.d` and `/etc/zulip/post-deploy.d`+directories are inspected for files ending with `.hook`, just before+and after the critical period when the server is restarted. Each file+is called, sorted in alphabetical order, from the working directory of+the new version, with arguments of the old and new Zulip versions. If+they exit with non-0 exit code, the upgrade will abort.+## Preserving local changes to service configuration files:::{warning}diff --git a/puppet/zulip/manifests/app_frontend_base.pp b/puppet/zulip/manifests/app_frontend_base.ppindex acc0a274cc3..ea7a0838e29 100644--- a/puppet/zulip/manifests/app_frontend_base.pp+++ b/puppet/zulip/manifests/app_frontend_base.pp@@ -5,6 +5,7 @@ class zulip::app_frontend_base {include zulip::sasl_modulesinclude zulip::supervisorinclude zulip::tornado_sharding+ include zulip::hooks::baseif $::os['family'] == 'Debian' {# Upgrade and other tooling wants to be able to get a databasediff --git a/puppet/zulip/manifests/hooks/base.pp b/puppet/zulip/manifests/hooks/base.ppnew file mode 100644index 00000000000..99adf87ef87--- /dev/null+++ b/puppet/zulip/manifests/hooks/base.pp@@ -0,0 +1,15 @@+# @summary Install sentry-cli binary and pre/post deploy hooks+#+class zulip::hooks::base {+ file { [+ '/etc/zulip/hooks',+ '/etc/zulip/hooks/pre-deploy.d',+ '/etc/zulip/hooks/post-deploy.d',+ ]:+ ensure => directory,+ owner => 'zulip',+ group => 'zulip',+ mode => '0755',+ tag => ['hooks'],+ }+}diff --git a/scripts/lib/upgrade-zulip-stage-2 b/scripts/lib/upgrade-zulip-stage-2index ddbf74ce50b..72f6316a439 100755--- a/scripts/lib/upgrade-zulip-stage-2+++ b/scripts/lib/upgrade-zulip-stage-2@@ -14,7 +14,7 @@ import shutilimport subprocessimport sysimport time-from typing import NoReturn, Optional+from typing import Literal, NoReturn, Optionalos.environ["PYTHONUNBUFFERED"] = "y"@@ -407,6 +407,13 @@ if not migrations_needed:["./manage.py", "fill_memcached_caches", "--skip-checks"], preexec_fn=su_to_zulip)+# Install hooks before we check for puppet changes, so we skip an+# unnecessary stop/start cycle if hook changes are the only ones.+logging.info("Installing hooks")+subprocess.check_call(+ ["./scripts/zulip-puppet-apply", "--tags", "hooks", "--force"],+)+# If we are planning on running puppet, we can pre-run it in --noop# mode and see if it will actually make any changes; if not, we can# skip it during the upgrade. We omit this check if the server is@@ -432,6 +439,19 @@ if not args.skip_puppet and IS_SERVER_UP:sys.exit(1)+def run_hooks(kind: Literal["pre-deploy", "post-deploy"]) -> None:+ # Updates to the above literal to add a new hook type should+ # adjust puppet's `app_frontend_base.pp` as well.+ path = f"/etc/zulip/hooks/{kind}.d"+ if not os.path.exists(path):+ return+ for script_name in sorted(f for f in os.listdir(path) if f.endswith(".hook")):+ subprocess.check_call(+ [os.path.join(path, script_name), old_version, NEW_ZULIP_VERSION],+ cwd=deploy_path,+ )++if args.skip_restart:logging.info("Successfully configured in %s!", deploy_path)else:@@ -440,6 +460,8 @@ else:# steps that happen between here and the "Restarting Zulip" line# below.+ run_hooks("pre-deploy")+if rabbitmq_dist_listen:shutdown_server()logging.info("Shutting down rabbitmq to adjust its ports...")@@ -491,6 +513,8 @@ else:logging.info("Upgrade complete!")+ run_hooks("post-deploy")+if args.audit_fts_indexes:logging.info("Correcting full-text search indexes for updated dictionary files")logging.info("This may take a while but the server should work while it runs.")