Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
scripts: Add a script to stop the server.
Alex Vandiver476524c0c19a
diff --git a/docs/production/export-and-import.md b/docs/production/export-and-import.mdindex 38c6e565b6d..08386be4cfc 100644--- a/docs/production/export-and-import.md+++ b/docs/production/export-and-import.md@@ -257,7 +257,7 @@ For best results, you'll want to shut down access to the organizationbefore exporting; so that nobody can send new messages (etc.) whileyou're exporting data. There are two ways to do this:-1. `supervisorctl stop all`, which stops the whole server. This is+1. `./scripts/stop-server`, which stops the whole server. This ispreferred if you're not hosting multiple organizations, because it hasno side effects other than disabling the Zulip server for theduration.@@ -282,7 +282,7 @@ following commands:```cd /home/zulip/deployments/current-# supervisorctl stop all # Stops the Zulip server+# ./scripts/stop-server# export DEACTIVATE_FLAG="--deactivate" # Deactivates the organization./manage.py export -r '' $DEACTIVATE_FLAG # Exports the data```@@ -316,7 +316,7 @@ archive of all the organization's uploaded files.several months of development ahead of the latest release.* Note that if your server has limited free RAM, you'll want to- shut down the Zulip server with `supervisorctl stop all` while+ shut down the Zulip server with `./scripts/stop-server` whileyou run the import, since our minimal system requirements do notbudget extra RAM for running the data import tool.diff --git a/docs/production/troubleshooting.md b/docs/production/troubleshooting.mdindex b2d25e8e059..21733d9d938 100644--- a/docs/production/troubleshooting.md+++ b/docs/production/troubleshooting.md@@ -87,6 +87,9 @@ Similarly, you can stop Zulip using:supervisorctl stop all```+If you're looking to shut down the server, it is often better to run+`./scripts/stop-server`.+## Troubleshooting servicesThe Zulip application uses several major open source services to storediff --git a/docs/production/upgrade-or-modify.md b/docs/production/upgrade-or-modify.mdindex b2d1730ad1a..04acfbbf36e 100644--- a/docs/production/upgrade-or-modify.md+++ b/docs/production/upgrade-or-modify.md@@ -415,7 +415,6 @@ To upgrade the version of PostgreSQL on the Zulip server:2. Stop the server and take a backup:```- sudo -i # Or otherwise get a root shellsupervisorctl stop all/home/zulip/deployments/current/manage.py backup --output=/home/zulip/postgresql-upgrade.backup.tar.gz```diff --git a/scripts/setup/postgresql-init-db b/scripts/setup/postgresql-init-dbindex 5a06229c1a6..230c077fbe2 100755--- a/scripts/setup/postgresql-init-db+++ b/scripts/setup/postgresql-init-db@@ -28,7 +28,7 @@ fi# Shut down all services to ensure a quiescent state.if [ -e "/var/run/supervisor.sock" ]; then- supervisorctl stop all+ su zulip -c "$(dirname "$(dirname "$0")")/stop-server"fi# Drop any open connections to any old database.diff --git a/scripts/stop-server b/scripts/stop-servernew file mode 100755index 00000000000..accc150f063--- /dev/null+++ b/scripts/stop-server@@ -0,0 +1,50 @@+#!/usr/bin/env python3+import logging+import os+import pwd+import subprocess+import sys+import time++sys.path.append(os.path.join(os.path.dirname(__file__), ".."))+from scripts.lib.zulip_tools import ENDC, OKGREEN, WARNING++deploy_path = os.path.realpath(os.path.join(os.path.dirname(__file__), ".."))+os.chdir(deploy_path)++if pwd.getpwuid(os.getuid()).pw_name != "zulip":+ logging.error("Must be run as user 'zulip'.")+ sys.exit(1)++logging.Formatter.converter = time.gmtime+logging.basicConfig(format="%(asctime)s stop-server: %(message)s", level=logging.INFO)++services = []++# Start with the least-critical services:+if os.path.exists("/etc/supervisor/conf.d/zulip/zulip_db.conf"):+ services.append("process-fts-updates")++if os.path.exists("/etc/supervisor/conf.d/zulip/thumbor.conf"):+ services.append("zulip-thumbor")++# Contrary to the order in (re)start-server, we stop django before the+# workers, to increase the chance that we finish processing any work+# that may have been enqueued by the Django, leaving the final state+# closer to "empty." We stop Django before Tornado so it doesn't try+# to make requests to make queues with a down'd Tornado.+services.append("zulip-django")+services.extend(["zulip-tornado", "zulip-tornado:*"])+services.append("zulip-workers:*")++subprocess.check_call(["supervisorctl", "stop", *services])++print()+print(OKGREEN + "Zulip stopped successfully!" + ENDC)++using_sso = subprocess.check_output(["./scripts/get-django-setting", "USING_APACHE_SSO"])+if using_sso.strip() == b"True":+ print()+ print(WARNING + "Apache2 needs to be shut down; as root, run:" + ENDC)+ print(" service apache2 stop")+ print()diff --git a/templates/zerver/help/import-from-gitter.md b/templates/zerver/help/import-from-gitter.mdindex dd44c19d792..01e61f45607 100644--- a/templates/zerver/help/import-from-gitter.md+++ b/templates/zerver/help/import-from-gitter.md@@ -49,7 +49,7 @@ the most common configuration, run the following commands:```cd /home/zulip/deployments/current-supervisorctl stop all # Stop the Zulip server+./scripts/stop-server./manage.py convert_gitter_data gitter_data.json --output converted_gitter_data./manage.py import '' converted_gitter_data./scripts/restart-serverdiff --git a/templates/zerver/help/import-from-mattermost.md b/templates/zerver/help/import-from-mattermost.mdindex 67848d41f7b..bfe109196fd 100644--- a/templates/zerver/help/import-from-mattermost.md+++ b/templates/zerver/help/import-from-mattermost.md@@ -149,7 +149,7 @@ the most common configuration, run the following commands, replacingcd /home/zuliptar -xzvf export.tar.gzcd /home/zulip/deployments/current-supervisorctl stop all # Stop the Zulip server+./scripts/stop-server./manage.py convert_mattermost_data /home/zulip/mattermost --output /home/zulip/converted_mattermost_data./manage.py import "" /home/zulip/converted_mattermost_data/<team-name>./scripts/restart-serverdiff --git a/templates/zerver/help/import-from-slack.md b/templates/zerver/help/import-from-slack.mdindex 2493905e6a1..bb385cbd479 100644--- a/templates/zerver/help/import-from-slack.md+++ b/templates/zerver/help/import-from-slack.md@@ -79,7 +79,7 @@ the most common configuration, run the following commands, replacing```cd /home/zulip/deployments/current-supervisorctl stop all # Stop the Zulip server+./scripts/stop-server./manage.py convert_slack_data slack_data.zip --token <token> --output converted_slack_data./manage.py import '' converted_slack_data./scripts/restart-serverdiff --git a/tools/ci/production-upgrade-pg b/tools/ci/production-upgrade-pgindex b59b74ad47e..91234a10f77 100755--- a/tools/ci/production-upgrade-pg+++ b/tools/ci/production-upgrade-pg@@ -3,10 +3,10 @@set -eset -x-ZULIP_PATH=/home/github/zulip+cd /home/github/zulip-supervisorctl stop all-"$ZULIP_PATH"/scripts/setup/upgrade-postgresql+su zulip -c ./scripts/stop-server+./scripts/setup/upgrade-postgresqlsupervisorctl start allecho "Upgrade of PostgreSQL complete!"