Commit Graph

1382 Commits

Author SHA1 Message Date
Anders Kaseorg 81bd63cb46 ruff: Fix PIE808 Unnecessary `start` argument in `range`.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-09-01 14:57:01 -07:00
Anders Kaseorg ead7b9177a check-database-compatibility: Ignore twofactor typo.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-08-23 22:14:26 -07:00
shu.chen 321776ac49
provision: Add provision support for Fedora 38.
Tweaked provision script to run successfully in Fedora 38 and
included a script to build the groonga libs from source because
the packages in Fedora repos are outdated.

There is a major version jump from the last supported version (F34)
which is EOL so references and support for older versions were
removed.

Fixes: #20635
2023-08-22 11:26:29 -07:00
Anders Kaseorg 344bfbf539 install-node: Upgrade Node.js from 18.17.0 to 18.17.1.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-08-17 18:16:47 -07:00
Anders Kaseorg c43629a222 ruff: Fix PLW1510 `subprocess.run` without explicit `check` argument.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-08-17 17:05:34 -07:00
David Rosa d205850d54 docs: Update .html links pointing to "Upgrade Zulip" or "Modify Zulip".
Follow-up to #24089.
2023-08-11 16:49:32 -07:00
Anders Kaseorg e932e2ce52 ruff: Fix UP032 Use f-string instead of `format` call.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-08-02 15:58:55 -07:00
Anders Kaseorg 5ccb408f19 build-pgroonga: Upgrade PGroonga from 3.0.3 to 3.1.0.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-07-25 17:33:42 -07:00
n0099 2b1d250154 nginx: Switch from `$host` to `$http_host` for HTTP/3 compatibility.
nginx sets the value of the `$http_host` variable to the empty string
when using http/3, as there is technically no `Host:` header sent:
https://github.com/nginx-quic/nginx-quic/issues/3

Users with a browser that support http/3 will send their first request
to nginx with http/2, and get an expected HTTP 200 -- but any
subsequent requests will fail with am HTTP 400, since the browser will
have upgraded to http/3, which has an empty `Host` header, which Zulip
rejects.

Switch to the `$host` variable, which works for all HTTP versions.

Co-authored-by: Alex Vandiver <alexmv@zulip.com>
2023-07-25 18:20:34 -04:00
Anders Kaseorg 2ae285af7c ruff: Fix PLR1714 Consider merging multiple comparisons.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-07-23 15:21:33 -07:00
Anders Kaseorg e890033f76 install-node: Upgrade Node.js from 18.16.0 to 18.17.0.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-07-21 15:58:42 -07:00
Anders Kaseorg b285813beb error_notify: Remove custom email error reporting handler.
Restore the default django.utils.log.AdminEmailHandler when
ERROR_REPORTING is enabled.  Those with more sophisticated needs can
turn it off and use Sentry or a Sentry-compatible system.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-07-20 11:00:09 -07:00
Alex Vandiver 1accc6929e upgrade: Check PostgreSQL versions after venv setup.
The claim in the comment from c8ec3dfcf6, that we can and should use
the current deploy's venv, misses one key case -- when upgrading the
operating system, the current deploy's venv is unworkable, since it
was configured for a previous version of Python.  As such, any attempt
to load Django to verify the version of PostgreSQL it is talking to
must happen after the venv is configured.

Move the database version check into
`scripts/lib/check-database-compatibility`, which also moves it after
the new venv is configured.

Because we no longer reliably know, at `apt-get upgrade` time, what
version of PostgreSQL is installed, we hold all versions of the
pgroonga packages.
2023-07-19 14:19:28 -07:00
Alex Vandiver 3bf83e8830 log-search: Prevent BrokenPipeError exceptions when run with `head`.
See https://docs.python.org/3/library/signal.html#note-on-sigpipe
2023-07-13 11:53:42 -07:00
Alex Vandiver 695295421a puppet: Upgrade Teleport to the 13.x series. 2023-07-13 11:46:51 -07:00
Alex Vandiver f5540303ba pgroonga: Remove 'GRANT USAGE' statement again.
dc2726c814 removed these statements, but c8ec3dfcf6 accidentally
brought one back.  Remove it.
2023-06-26 10:47:17 -04:00
Alex Vandiver ec4bfd7c78 install: Use the initially-cloned repo as the base /srv/zulip.git.
This ensures that the next `upgrade-zulip-from-git` has access to the
commit history of the initial install, if it was from a forked
repository.  `/home/zulip/deployments/current` and `/srv/zulip.git`
are not quite organized into the steady-state that they will have
after one `upgrade-zulip-from-git`:
 - `/home/zulip/deployments/current` is its own clone, not a worktree
 - `/srv/zulip.git` has an origin of `/home/zulip/deployments/current`
 - `remote.origin.mirror` is set on `/srv/zulip.git`
 - `remote.origin.fetch` is `+refs/*:refs/*`

All but the first are automatically cleaned up by
`upgrade-zulip-from-git` when it is next run, using the code added in
30457ecd02.  The additional complexity of making an existing
independent clone into a worktree seem not worth solving the first
point.
2023-06-24 07:43:04 -07:00
Alex Vandiver 1276653ec8 upgrade-zulip: The "git rev-parse" command can parse "git describe" output directly. 2023-06-24 07:43:04 -07:00
Alex Vandiver c8ec3dfcf6 pgroonga: Run upgrade SQL when pgroonga package is updated.
Updating the pgroonga package is not sufficient to upgrade the
extension in PostgreSQL -- an `ALTER EXTENSION pgroonga UPDATE` must
explicitly be run[^1].  Failure to do so can lead to unexpected behavior,
including crashes of PostgreSQL.

Expand on the existing `pgroonga_setup.sql.applied` file, to track
which version of the PostgreSQL extension has been configured.  If the
file exists but is empty, we run `ALTER EXTENSION pgroonga UPDATE`
regardless -- if it is a no-op, it still succeeds with a `NOTICE`:

```
zulip=# ALTER EXTENSION pgroonga UPDATE;
NOTICE:  version "3.0.8" of extension "pgroonga" is already installed
ALTER EXTENSION
```

The simple `ALTER EXTENSION` is sufficient for the
backwards-compatible case[^1] -- which, for our usage, is every
upgrade since 0.9 -> 1.0.  Since version 1.0 was released in 2015,
before pgroonga support was added to Zulip in 2016, we can assume for
the moment that all pgroonga upgrades are backwards-compatible, and
not bother regenerating indexes.

Fixes: #25989.

[^1]: https://pgroonga.github.io/upgrade/
2023-06-23 14:40:27 -07:00
Alex Vandiver dc2726c814 pgroonga: Remove now-unnecessary 'GRANT USAGE' statement.
This was only necessary for PGroonga 1.x, and the `pgroonga` schema
will most likely be removed at some point inthe future, which will
make this statement error out.

Drop the unnecessary statement.
2023-06-23 14:40:27 -07:00
Alex Vandiver 875502b2e1 upgrade-postgresql: Only upgrade to a supported version. 2023-06-12 16:37:55 -07:00
Alex Vandiver a472667ca1 upgrade-zulip: Verify postgresql.version against where data is stored.
This prevents installing a PostgreSQL server which matches
/etc/zulip/zulip.conf but which has no data and is not used by Django.
2023-06-07 14:59:54 -07:00
Alex Vandiver b9210e3ed9 upgrade-zulip: Set postgresql.version from running version, not a guess. 2023-06-07 14:59:54 -07:00
Alex Vandiver 6dc8f748ae upgrade-zulip: Simplify PostgreSQL version check.
This is much simpler now that we do not support PostgreSQL 9.x.
2023-06-07 14:59:54 -07:00
Alex Vandiver 1f68726cb8 upgrade-postgresql: Prevent upgrades if /etc/zulip/zulip.conf is wrong.
If the `postgresql.version` in `/etc/zulip/zulip.conf` is out of date
or wrong, upgrading to the actual current version would drop your
production database without prompting.  While we do document taking a
Zulip backup (which includes a database backup) before running
`upgrade-postgresql`[^1], not everyone does so, with possibly
catastrophic consequences.

Do a true end-to-end check of the version in `/etc/zulip/zulip.conf`
by asking Django to query the database for its version, checking that
against the configured value, and aborting if there is any
disagreement.

[^1]: https://zulip.readthedocs.io/en/latest/production/upgrade.html#upgrading-postgresql
2023-06-07 14:59:54 -07:00
Alex Vandiver 32e1384ca0 upgrade-postgresql: Prevent PostgreSQL downgrades. 2023-06-07 14:59:54 -07:00
Alex Vandiver 501d38b781 upgrade-postgresql: Check for undefined variables. 2023-06-07 14:59:54 -07:00
Anders Kaseorg f3684e842a install: Check CPU and OS architecture.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-06-01 17:09:48 -07:00
Anders Kaseorg 37040ac49d install: Add system_requirements_failure helper.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-06-01 17:09:48 -07:00
Anders Kaseorg 12310189ed install: Support Debian 12.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-05-18 11:52:22 -07:00
Anders Kaseorg 83c0ed2a9d build-pgroonga: Upgrade PGroonga from 2.3.6 to 3.0.3.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-05-18 11:52:22 -07:00
Alex Vandiver 0da62e7cda supervisor: Retry, with backoff, to connect to supervisor socket.
If `zulip-puppet-apply` is run during an upgrade, it will immediately
try to re-`stop-server` before running migrations; if the last step in
the puppet application was to restart `supervisor`, it may not be
listening on its UNIX socket yet.  In such cases, `socket.connect()`
throws a `FileNotFoundError`:

```
Traceback (most recent call last):
  File "./scripts/stop-server", line 53, in <module>
    services = list_supervisor_processes(services, only_running=True)
  File "./scripts/lib/supervisor.py", line 34, in list_supervisor_processes
    processes = rpc().supervisor.getAllProcessInfo()
  File "/usr/lib/python3.9/xmlrpc/client.py", line 1116, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib/python3.9/xmlrpc/client.py", line 1456, in __request
    response = self.__transport.request(
  File "/usr/lib/python3.9/xmlrpc/client.py", line 1160, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/usr/lib/python3.9/xmlrpc/client.py", line 1172, in single_request
    http_conn = self.send_request(host, handler, request_body, verbose)
  File "/usr/lib/python3.9/xmlrpc/client.py", line 1285, in send_request
    self.send_content(connection, request_body)
  File "/usr/lib/python3.9/xmlrpc/client.py", line 1315, in send_content
    connection.endheaders(request_body)
  File "/usr/lib/python3.9/http/client.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.9/http/client.py", line 1010, in _send_output
    self.send(msg)
  File "/usr/lib/python3.9/http/client.py", line 950, in send
    self.connect()
  File "./scripts/lib/supervisor.py", line 10, in connect
    self.sock.connect(self.host)
FileNotFoundError: [Errno 2] No such file or directory
```

Catch the `FileNotFoundError` and retry twice more, with backoff.  If
it fails repeatedly, point to `service supervisor status` for further
debugging, as `FileNotFoundError` is rather misleading -- the file
exists, it simply is not accepting connections.
2023-05-12 13:14:27 -07:00
Alex Vandiver b8f53ab6e8 supervisor: Include STARTING processes in 'only_running' processes.
Because `STARTING` processes are on their way up, they should
effectively be counted as `RUNNING`, since the passage of time will
make them so.
2023-05-12 13:14:27 -07:00
Alex Vandiver f4683de742 puppet: Switch the `rolling_restart` setting to use the bool values.
2c5fc1827c standardized which values are "true"; use them.
2023-05-11 15:54:15 -07:00
Alex Vandiver 530980cf31 zulip_tools: Add a get_config_bool to match Puppet logic.
Unfortunately, the existing use of this logic in `process_fts_updates`
cannot switch to using this code, as that code cannot import
zulip_tools.
2023-05-11 15:54:15 -07:00
Alex Vandiver f11350f789 puppet: Add PostgreSQL 15 support.
Instead of copying over a mostly-unchanged `postgresql.conf`, we
transition to deploying a `conf.d/zulip.conf` which contains the
only material changes we made to the file, which were previously
appended to the end.

While shipping separate while `postgresql.conf` files for each
supported version is useful if there is large variety in supported
options between versions, there is not no such variation at current,
and the burden of overriding the entire default configuration is that
it must be keep up to date wit the package's version.
2023-05-10 14:06:02 -07:00
Anders Kaseorg 3bc1acba4a install: Use set -x when installing node, shellcheck, shfmt, tx.
This makes it clearer which step failed if there’s an error.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-05-10 12:15:34 -07:00
Alex Vandiver 94495bef18 log-search: Filter out /error_tracing endpoints. 2023-05-05 14:45:46 -07:00
Alex Vandiver 7e637786b3 upgrade-postgresql: Only try to start new cluster if it is stopped.
pg_upgradecluster will start the cluster if the old cluster was
started before it ran, or if there are post-upgrade scripts to run.
Because neither of those are fully under our control, only attempt to
start the new cluster if it isn't already.
2023-05-05 13:35:32 -07:00
Alex Vandiver 40e5a12e3c upgrade-postgresql: Use jq rather than grep to check cluster status. 2023-05-05 13:35:32 -07:00
Alex Vandiver e5ae55637e install: Remove PostgreSQL 11 support.
Django 4.2 removes this support, so Zulip has not installed with
PostgreSQL 11 since 2c20028aa4.
2023-05-05 13:35:32 -07:00
Anders Kaseorg a31ff01211 node_cache: Disable pnpm update check.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-05-02 12:29:38 -07:00
Anders Kaseorg 6c4705a4ef install-node: Upgrade Node.js from 18.15.0 to 18.16.0.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-04-25 22:18:48 -07:00
Alex Vandiver 63e31a6de4 upgrade-zulip-from-git: CWD will be the cache directory.
96e42b8e81 broke this when it split out the steps to reset the
upstream.
2023-04-24 17:19:27 -07:00
Alex Vandiver c815dba368 install: Write out a zulip-git-version upon install. 2023-04-19 16:56:14 -07:00
Alex Vandiver 8ae167dc05 upgrade-zulip-from-git: We may need to fill in a zulip-git-version file.
Installs which are upgrading to current `main`, and are upgrading for
the very first time from an install which was originally from git,
have a `/home/zulip/deployments/current` which, unlike all later
upgrades, is not a `git worktree` of `/srv/zulip.git`, but rather a
direct `git clone` of some arbitrary URL.  As such, it does not have
an `upstream` remote, nor a cached `zulip-git-version` file.

This makes later attempts to determine the pre-upgrade revision of
git (for pre-deploy hooks) fail, as without a `zulip-git-version`
file, `ZULIP_VERSION` is insufficiently-specific (e.g. `6.1+git`), and
there is no guarantee the necessary tags exist either.

While we can make fresh git installs set up an `upstream` and run
`./tools/cache-zulip-git-version` going forward (see subsequent
commit), that does not address the issue for deploys which already
exist.  For those, we must configure and fetch a `remote` in the old
checkout, followed by re-generating a cached `zulip-git-version`.

Fixes: #25076.
2023-04-19 16:56:14 -07:00
Alex Vandiver 96e42b8e81 upgrade-zulip-from-git: Extract code to set zulip upstream remote. 2023-04-19 16:56:14 -07:00
Alex Vandiver 7dc7962c04 zulip-puppet-apply: Any resources failing to apply should exit 2.
The existing `except subprocess.CalledProcessError` only catches if
there are syntax errors which prevent the `lastrun` file from being
written; it does not handle if there are properly-defined resources
which fail to evaluate (e.g. due to a missing dependency or file).

Check the `failed` resource count, and exit 2 if there are any such
resources.  This will cause `zulip-puppet-apply --force --noop` (which
is used as a pre-flight check during upgrades) to properly detect and
signal on more types of invalid puppet configurations.  In turn, this
will cause `upgrade-zulip` to not attempt to power through upgrades it
knows are destined to fail.
2023-04-19 09:35:19 -07:00
Alex Vandiver 7c023042cf puppet: Rotate access log files every day, not at 500M.
Since logrotate runs in a daily cron, this practically means "daily,
but only if it's larger than 500M."  For large installs with large
traffic, this is effectively daily for 10 days; for small installs, it
is an unknown amount of time.

Switch to daily logfiles, defaulting to 14 days to match nginx; this
can be overridden using a zulip.conf setting.  This makes it easier to
ensure that access logs are only kept for a bounded period of time.
2023-04-06 14:31:16 -04:00
Alex Vandiver f4d70a2e37 hooks: Resolve version strings to commit SHAs, and pass in via the env. 2023-04-05 18:51:55 -04:00