Faidon Liambotis has submitted this change and it was merged. Change subject: Add 'graphite-index' script and cron job ......................................................................
Add 'graphite-index' script and cron job The graphite-web package ships with a shell script, 'graphite-build-search-index', which rebuilds the index of Whisper files used by graphite-web. The Debian script presumes that graphite-web and carbon are both running with uid / gid '_graphite', but we prefer to keep them distinct, because graphite-web should not be modifying Whisper files. So ship an alternative script that better matches our setup. Change-Id: I83a2c6dbecba7545bb6e849f4e0089d69f202f44 --- A modules/graphite/files/graphite-index M modules/graphite/manifests/web.pp 2 files changed, 54 insertions(+), 6 deletions(-) Approvals: Faidon Liambotis: Looks good to me, approved jenkins-bot: Verified diff --git a/modules/graphite/files/graphite-index b/modules/graphite/files/graphite-index new file mode 100755 index 0000000..f9932c8 --- /dev/null +++ b/modules/graphite/files/graphite-index @@ -0,0 +1,35 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" + Generate index file for graphite-web + + This file supercedes the script 'graphite-build-search-index' which ships + with the graphite-web package in Debian. The Debian script presumes that + graphite-web and carbon are both running with uid / gid '_graphite', but we + prefer to keep them distinct, because graphite-web should not be modifying + Whisper files. + +""" +import os +import fnmatch +import tempfile + +from graphite import settings + + +def iter_glob(dir, glob_pattern): + """Recurse through `dir`, yielding files that match `glob_pattern`""" + return (os.path.join(root, f) for root, _, fs in os.walk(dir) + for f in fs if fnmatch.fnmatch(f, glob_pattern)) + + +def format_entry(wsp_path): + """Format a .wsp file path for inclusion in Graphite's index""" + return wsp_path[len(settings.WHISPER_DIR):-4].replace('/', '.') + + +with tempfile.NamedTemporaryFile('wt', delete=False) as tmp: + for whisper in iter_glob(settings.WHISPER_DIR, '*.wsp'): + tmp.write(format_entry(whisper) + '\n') + os.chmod(tmp.name, 0644) + os.rename(tmp.name, settings.INDEX_FILE) diff --git a/modules/graphite/manifests/web.pp b/modules/graphite/manifests/web.pp index f0ebfcf..b579b8b 100644 --- a/modules/graphite/manifests/web.pp +++ b/modules/graphite/manifests/web.pp @@ -96,15 +96,28 @@ require => File['/var/run/graphite-web', '/var/log/graphite-web'], } - file { '/sbin/graphite-auth': - source => 'puppet:///modules/graphite/graphite-auth', - mode => '0755', + file { '/usr/local/sbin/graphite-index': + source => 'puppet:///modules/graphite/graphite-index', + mode => '0555', require => Uwsgi::App['graphite-web'], } + file { '/usr/local/sbin/graphite-auth': + source => 'puppet:///modules/graphite/graphite-auth', + mode => '0555', + require => Uwsgi::App['graphite-web'], + } + + cron { 'update_graphite_index': + command => '/usr/local/sbin/graphite-index', + user => 'www-data', + hour => '*/1', + require => File['/usr/local/sbin/graphite-index'], + } + exec { 'create_graphite_admin': - command => "/sbin/graphite-auth set ${admin_user} ${admin_pass}", - unless => "/sbin/graphite-auth check ${admin_user} ${admin_pass}", - require => File['/sbin/graphite-auth'], + command => "/usr/local/sbin/graphite-auth set ${admin_user} ${admin_pass}", + unless => "/usr/local/sbin/graphite-auth check ${admin_user} ${admin_pass}", + require => File['/usr/local/sbin/graphite-auth'], } } -- To view, visit https://gerrit.wikimedia.org/r/107616 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I83a2c6dbecba7545bb6e849f4e0089d69f202f44 Gerrit-PatchSet: 4 Gerrit-Project: operations/puppet Gerrit-Branch: production Gerrit-Owner: Ori.livneh <o...@wikimedia.org> Gerrit-Reviewer: Faidon Liambotis <fai...@wikimedia.org> Gerrit-Reviewer: Ori.livneh <o...@wikimedia.org> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits