diff --git a/modules/elastic_recheck/files/er_safe_run.sh b/modules/elastic_recheck/files/er_safe_run.sh new file mode 100755 index 0000000000..0a550a30c7 --- /dev/null +++ b/modules/elastic_recheck/files/er_safe_run.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +flock /var/lib/elastic-recheck/er_safe_run.lock $@ diff --git a/modules/elastic_recheck/manifests/cron.pp b/modules/elastic_recheck/manifests/cron.pp new file mode 100644 index 0000000000..37bf006844 --- /dev/null +++ b/modules/elastic_recheck/manifests/cron.pp @@ -0,0 +1,42 @@ +# Copyright 2013 Hewlett-Packard Development Company, L.P. +# Copyright 2014 Samsung Electronics +# +# 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. +# +# Class to install and configure an instance of the elastic-recheck +# service. +# + +class elastic_recheck::cron () { + $er_state_path = $::elastic_recheck::recheck_state_dir + $graph_cmd = $::elastic_recheck::graph_cmd + $uncat_cmd = $::elastic_recheck::uncat_cmd + + cron { 'elastic-recheck': + user => 'recheck', + minute => '*/15', + hour => '*', + command => "cd ${er_state_path}; er_safe_run.sh ${graph_cmd}", + environment => 'PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin', + require => Class['elastic_recheck'] + } + + cron { 'elastic-recheck-uncat': + user => 'recheck', + minute => '59', + hour => '*', + command => "cd ${er_state_path}; er_safe_run.sh ${graph_cmd}", + environment => 'PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin', + require => Class['elastic_recheck'] + } +} diff --git a/modules/elastic_recheck/manifests/init.pp b/modules/elastic_recheck/manifests/init.pp index d431bc2384..f8e3de37d5 100644 --- a/modules/elastic_recheck/manifests/init.pp +++ b/modules/elastic_recheck/manifests/init.pp @@ -17,6 +17,15 @@ # class elastic_recheck ( ) { + + # For all static page generation scripts we want to run them + # both on a cron schedule (see elastic_recheck::cron) and on + # any commit. So we need to define commands in a way that + # we can trigger an exec here, as well as on cron. + $recheck_state_dir = '/var/lib/elastic-recheck' + $graph_cmd = 'elastic-recheck-graph /opt/elastic-recheck/queries -o graph-new.json && mv graph-new.json graph.json' + $uncat_cmd = 'elastic-recheck-uncategorized -d /opt/elastic-recheck/queries -t /usr/local/share/templates -o uncategorized-new.html && mv uncategorized-new.html uncategorized.html' + group { 'recheck': ensure => 'present', } @@ -36,6 +45,24 @@ class elastic_recheck ( source => 'https://git.openstack.org/openstack-infra/elastic-recheck', } + exec { 'run_er_graph': + command => "cd ${recheck_state_dir} && er_safe_run.sh ${graph_cmd}", + path => '/usr/local/bin:/usr/bin:/bin/', + user => 'recheck', + refreshonly => true, + require => File['/usr/local/bin/er_safe_run.sh'], + subscribe => Vcsrepo['/opt/elastic-recheck'], + } + + exec { 'run_er_uncat': + command => "cd ${recheck_state_dir} && er_safe_run.sh ${uncat_cmd}", + path => '/usr/local/bin:/usr/bin:/bin/', + user => 'recheck', + refreshonly => true, + require => File['/usr/local/bin/er_safe_run.sh'], + subscribe => Vcsrepo['/opt/elastic-recheck'], + } + include pip exec { 'install_elastic-recheck' : command => 'pip install /opt/elastic-recheck', @@ -45,6 +72,14 @@ class elastic_recheck ( require => Class['pip'], } + file { '/usr/local/bin/er_safe_run.sh': + ensure => present, + source => 'puppet:///modules/elastic_recheck/er_safe_run.sh', + mode => '0755', + owner => 'root', + group => 'root', + } + file { '/var/run/elastic-recheck': ensure => directory, mode => '0755', diff --git a/modules/openstack_project/manifests/status.pp b/modules/openstack_project/manifests/status.pp index 36ea9b82df..16fde14102 100644 --- a/modules/openstack_project/manifests/status.pp +++ b/modules/openstack_project/manifests/status.pp @@ -12,7 +12,6 @@ class openstack_project::status ( $recheck_ssh_private_key, $recheck_bot_passwd, $recheck_bot_nick, - $recheck_state_dir = '/var/lib/elastic-recheck', ) { class { 'openstack_project::server': @@ -138,15 +137,6 @@ class openstack_project::status ( # Status - elastic-recheck include elastic_recheck - cron { 'elastic-recheck': - user => 'recheck', - minute => '*/15', - hour => '*', - command => "elastic-recheck-graph /opt/elastic-recheck/queries -o ${recheck_state_dir}/graph-new.json && mv ${recheck_state_dir}/graph-new.json ${recheck_state_dir}/graph.json", - environment => 'PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin', - require => Class['elastic_recheck'] - } - class { 'elastic_recheck::bot': gerrit_host => $gerrit_host, gerrit_ssh_host_key => $gerrit_ssh_host_key, @@ -156,6 +146,9 @@ class openstack_project::status ( recheck_bot_nick => $recheck_bot_nick, } + # sets up the cron update scripts for static pages + include elastic_recheck::cron + ########################################################### # Status - zuul