Merge "Fixes for codesearch resync"

This commit is contained in:
Zuul 2017-12-14 04:05:13 +00:00 committed by Gerrit Code Review
commit 3bbc2be599
2 changed files with 100 additions and 13 deletions

View 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}

View File

@ -19,18 +19,41 @@ class openstack_project::codesearch (
ensure => 'present', ensure => 'present',
} }
exec { 'create-hound-config': file { '/usr/local/bin/resync-hound-config':
command => 'create-hound-config', ensure => present,
path => '/bin:/usr/bin:/usr/local/bin', owner => 'root',
environment => "PROJECTS_YAML=${::project_config::jeepyb_project_file}", group => 'root',
user => 'hound', mode => '0755',
cwd => '/home/hound', source => 'puppet:///modules/openstack_project/resync-hound-config.sh',
require => [ }
$::project_config::config_dir,
File['/home/hound'], # 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'],
], ],
notify => Service['hound'],
refreshonly => true,
subscribe => Class['project_config'],
} }
logrotate::file { 'hound-sync':
log => '/var/log/hound.sync.log',
options => [
'compress',
'copytruncate',
'missingok',
'rotate 7',
'daily',
'notifempty',
],
}
} }