From 0e2f921b7e311da5b42aa392df4f9857f70e0d42 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Wed, 12 Feb 2014 15:52:29 +0100 Subject: [PATCH] Add flush_cache script. Closes #140 --- tools/flush_cache | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 tools/flush_cache diff --git a/tools/flush_cache b/tools/flush_cache new file mode 100755 index 00000000..fdf3bb83 --- /dev/null +++ b/tools/flush_cache @@ -0,0 +1,59 @@ +#!/usr/bin/env node + +var path = require('path'); +var request = require('request'); + +function usage(me, exitcode) { + console.log("Usage: " + me + " [--env ] "); + process.exit(exitcode); +} + +var node_path = process.argv.shift(); +var script_path = process.argv.shift(); +var basedir = path.dirname(script_path); +var me = path.basename(script_path); + +var ENV = 'development.js'; +var username, table; +var arg; +while ( arg = process.argv.shift() ) { + if ( arg == '--env' ) { + ENV = process.argv.shift(); + } + else if ( ! username ) { + username = arg; + } + else if ( ! table ) { + table = arg; + } + else { + console.warn("Unused parameter " + arg); + } +} + +if ( ! table ) { + usage(me, 1); +} + +global.environment = require('../config/environments/' + ENV); + +// _after_ setting global.environment +var serverOptions = require('../lib/cartodb/server_options'); + +var host = global.environment.host; +var port = global.environment.port; +var re = ''+serverOptions.re_userFromHost; +var hostname = re.replace(/^\/\^/, '') + .replace(/\/$$/, '') + .replace(/\\/g,'') + .replace(/\([^)]*\)/,username) + ; +//console.log("re: " + re); +//console.log("hostname: " + hostname); + +var url = 'http://' + host + ':' + port + '/tiles/' + table + '/flush_cache'; +request.del({ url: url, headers: { host: hostname } }, +function(err, res, body) { + if ( err ) throw err; + console.log(res.body); +});