flush-memcached: Respect MEMCACHED_LOCATION; handle errors.

Fixes #13238.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg
2019-10-01 14:42:35 -07:00
parent 23c48764b5
commit 0af22dad18
4 changed files with 28 additions and 9 deletions

View File

@@ -1,6 +1,25 @@
#!/usr/bin/env bash
set -e
#!/usr/bin/env python3
# Flush memcached
echo "Flushing memcached..."
echo 'flush_all' | nc -w 1 localhost 11211
import os
import socket
import sys
from urllib.parse import urlsplit
BASE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../..")
sys.path.append(BASE_DIR)
import scripts.lib.setup_path_on_import
from zproject import settings
url = urlsplit("//" + settings.MEMCACHED_LOCATION)
print("Flushing memcached...")
with socket.create_connection((url.hostname, url.port)) as f:
f.sendall(b"flush_all\r\n")
response = b""
while b"\n" not in response:
response += f.recv(4096)
if response != b"OK\r\n":
print(response, file=sys.stderr)
print("Failed to flush memcached", file=sys.stderr)
sys.exit(1)

View File

@@ -9,7 +9,7 @@ DROP DATABASE IF EXISTS zulip;
CREATE DATABASE zulip TEMPLATE zulip_base;
EOF
sh "$(dirname "$0")/../scripts/setup/flush-memcached"
"$(dirname "$0")/../scripts/setup/flush-memcached"
./manage.py purge_queue --all
./manage.py migrate --noinput

View File

@@ -17,7 +17,7 @@ if [ "$1" != "--force" ]; then
DROP DATABASE IF EXISTS zulip_test;
CREATE DATABASE zulip_test TEMPLATE zulip_test_template;
EOF
sh "$(dirname "$0")/../../scripts/setup/flush-memcached"
"$(dirname "$0")/../../scripts/setup/flush-memcached"
exit 0
fi
@@ -29,7 +29,7 @@ psql -v ON_ERROR_STOP=1 -h localhost postgres zulip_test <<EOF
DROP DATABASE IF EXISTS zulip_test;
CREATE DATABASE zulip_test TEMPLATE zulip_test_base;
EOF
sh "$(dirname "$0")/../../scripts/setup/flush-memcached"
"$(dirname "$0")/../../scripts/setup/flush-memcached"
./manage.py migrate --noinput
./manage.py get_migration_status --output="migration_status_test"

View File

@@ -106,6 +106,6 @@ psql -v ON_ERROR_STOP=1 -e -h localhost postgres "$USERNAME" <<EOF
CREATE DATABASE $DBNAME TEMPLATE $DBNAME_BASE;
EOF
sh "$(dirname "$0")/../../scripts/setup/flush-memcached"
"$(dirname "$0")/../../scripts/setup/flush-memcached"
echo "Database created"