system-config/modules/openstack_project/files/resync-hound-config.sh
Ian Wienand 795bf1c971 Fixes for codesearch resync
This provides a script to resync the hound configuration for
codesearch.

It checks if the config needs updating, and if so, puts the new config
file in place, takes the reindex lock from
I9d28201bca75b624e07cbba14c870151094fc7ae and restarts the service,
waiting until it sees it is up.

puppet is currently disabled on this host because updates are tied to
project-config changes; since restarting takes the service down this
is obviously not great.

Change-Id: Iaebf50836607da447dcf1765ec01d0121537b0da
Depends-On: I9d28201bca75b624e07cbba14c870151094fc7ae
2017-12-14 09:48:01 +11:00

65 lines
1.7 KiB
Bash

#!/bin/bash
# Copyright 2017 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
PROJECTS_YAML=${PROJECTS_YAML:-/etc/project-config/gerrit/projects.yaml}
REINDEX_LOCK=/var/www/hound/reindex.lock
TEMP_DIR=$(mktemp -d)
pushd ${TEMP_DIR}
echo "Starting hound config update"
# Generate the new config
PROJECTS_YAML=${PROJECTS_YAML} create-hound-config
# See if we need to update
NEW="$(md5sum config.json | awk '{print $1}')"
OLD="$(md5sum /home/hound/config.json | awk '{print $1}')"
if [[ ${NEW} == ${OLD} ]]; then
echo "Nothing to do"
rm -rf ${TEMP_DIR}
exit 0
fi
echo "Recreating config"
# Move the new config into place
chown hound:hound config.json
chmod 0644 config.json
cp /home/hound/config.json /home/hound/config.json.bak
mv ./config.json /home/hound/config.json
# release the hounds
touch ${REINDEX_LOCK}
service hound stop
sleep 2
service hound start
# Hound takes a few minutes to go through all our projects. We know
# it's ready when we see it listening on port 6080
echo "Waiting for hound..."
while ! netstat -lnt | grep -q ':6080.*LISTEN\s*$' ; do
echo " ... still waiting"
sleep 5
done
rm ${REINDEX_LOCK}
echo "... done"
popd
rm -rf ${TEMP_DIR}