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
This commit is contained in:
parent
ea950aadeb
commit
795bf1c971
64
modules/openstack_project/files/resync-hound-config.sh
Normal file
64
modules/openstack_project/files/resync-hound-config.sh
Normal file
@ -0,0 +1,64 @@
|
||||
#!/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}
|
@ -19,18 +19,41 @@ class openstack_project::codesearch (
|
||||
ensure => 'present',
|
||||
}
|
||||
|
||||
exec { 'create-hound-config':
|
||||
command => 'create-hound-config',
|
||||
path => '/bin:/usr/bin:/usr/local/bin',
|
||||
environment => "PROJECTS_YAML=${::project_config::jeepyb_project_file}",
|
||||
user => 'hound',
|
||||
cwd => '/home/hound',
|
||||
require => [
|
||||
$::project_config::config_dir,
|
||||
File['/home/hound'],
|
||||
],
|
||||
notify => Service['hound'],
|
||||
refreshonly => true,
|
||||
subscribe => Class['project_config'],
|
||||
file { '/usr/local/bin/resync-hound-config':
|
||||
ensure => present,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0755',
|
||||
source => 'puppet:///modules/openstack_project/resync-hound-config.sh',
|
||||
}
|
||||
|
||||
# Note: we could trigger this from project-config changes, but it
|
||||
# does bring the service down for several minutes if something
|
||||
# changes. Once a day should be enough.
|
||||
cron { 'hound':
|
||||
user => root,
|
||||
hour => '4',
|
||||
command => 'flock -n /var/run/hound/sync.lock resync-hound-config 2>&1 >> /var/log/hound.sync.log',
|
||||
environment => [
|
||||
'PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin',
|
||||
"PROJECTS_YAML=${::project_config::jeepyb_project_file}",
|
||||
],
|
||||
require => [
|
||||
File['/usr/local/bin/resync-hound-config'],
|
||||
File['/home/hound/config.json'],
|
||||
],
|
||||
}
|
||||
|
||||
logrotate::file { 'hound-sync':
|
||||
log => '/var/log/hound.sync.log',
|
||||
options => [
|
||||
'compress',
|
||||
'copytruncate',
|
||||
'missingok',
|
||||
'rotate 7',
|
||||
'daily',
|
||||
'notifempty',
|
||||
],
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user