2021-04-16 07:46:05 +02:00
|
|
|
#!/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__), ".."))
|
2023-10-12 20:40:54 +02:00
|
|
|
from scripts.lib.setup_path import setup_path
|
|
|
|
|
|
|
|
setup_path()
|
|
|
|
|
2022-01-20 01:01:13 +01:00
|
|
|
from scripts.lib.supervisor import list_supervisor_processes
|
2021-05-14 03:08:38 +02:00
|
|
|
from scripts.lib.zulip_tools import (
|
|
|
|
ENDC,
|
|
|
|
OKGREEN,
|
|
|
|
WARNING,
|
|
|
|
has_application_server,
|
|
|
|
has_process_fts_updates,
|
2024-02-07 20:57:28 +01:00
|
|
|
su_to_zulip,
|
2021-05-14 03:08:38 +02:00
|
|
|
)
|
2021-04-16 07:46:05 +02:00
|
|
|
|
|
|
|
deploy_path = os.path.realpath(os.path.join(os.path.dirname(__file__), ".."))
|
|
|
|
os.chdir(deploy_path)
|
|
|
|
|
2024-02-07 20:57:28 +01:00
|
|
|
username = pwd.getpwuid(os.getuid()).pw_name
|
|
|
|
if username == "root":
|
|
|
|
su_to_zulip()
|
|
|
|
elif username != "zulip":
|
2021-04-16 07:46:05 +02:00
|
|
|
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:
|
2021-05-14 03:08:38 +02:00
|
|
|
if has_process_fts_updates():
|
2021-04-16 07:46:05 +02:00
|
|
|
services.append("process-fts-updates")
|
|
|
|
|
2021-04-27 20:48:19 +02:00
|
|
|
if has_application_server():
|
|
|
|
# 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")
|
2021-12-08 19:22:30 +01:00
|
|
|
services.append("zulip-tornado:*")
|
2021-04-27 20:48:19 +02:00
|
|
|
services.append("zulip-workers:*")
|
2021-06-11 22:58:09 +02:00
|
|
|
if has_application_server(once=True):
|
2022-03-26 00:44:26 +01:00
|
|
|
# These used to be included in "zulip-workers:*"; we may be
|
|
|
|
# stopping an older version of Zulip, which has not applied
|
|
|
|
# puppet to reload the new list of processes, but the
|
|
|
|
# list_supervisor_processes below will filter them out if they
|
|
|
|
# do not exist.
|
|
|
|
services.append("zulip_deliver_scheduled_emails")
|
|
|
|
services.append("zulip_deliver_scheduled_messages")
|
2021-04-16 07:46:05 +02:00
|
|
|
|
2022-03-26 00:44:26 +01:00
|
|
|
services = list_supervisor_processes(services, only_running=True)
|
|
|
|
if services:
|
|
|
|
subprocess.check_call(["supervisorctl", "stop", *services])
|
2021-04-16 07:46:05 +02:00
|
|
|
|
|
|
|
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()
|