From 9ce3e2a4e56f91fdc7d6295d3d064f2739955404 Mon Sep 17 00:00:00 2001 From: Paul J R Date: Tue, 25 Jun 2013 08:57:50 +1000 Subject: [PATCH] cache maintenance remove routine added - needs a real one --- TODO | 3 +-- lib/config.js | 2 +- lib/log.js | 10 +++++----- lib/maintain.js | 40 ++++++++++++++++++++++++++++++++++++++-- lib/repo-yum.js | 2 +- proxy.js | 5 +++-- repos.conf | 2 +- 7 files changed, 50 insertions(+), 14 deletions(-) diff --git a/TODO b/TODO index 56a27c9..7d7a5f8 100644 --- a/TODO +++ b/TODO @@ -2,5 +2,4 @@ TODO ==== - fix the log.* entries that need to be errors -- metadata check on maintenance routines -- \ No newline at end of file +- metadata check on maintenance routines \ No newline at end of file diff --git a/lib/config.js b/lib/config.js index 8af15f0..b995b41 100644 --- a/lib/config.js +++ b/lib/config.js @@ -67,7 +67,7 @@ exports.loadConfig = function (conffile) { default: if(line_real[0] != "") { - log.info("WARNING Invalid line in configuration file ignored: '%s'", line_one); + log.warning("Invalid line in configuration file ignored: '%s'", line_one); } } } diff --git a/lib/log.js b/lib/log.js index 6cb7e21..49e189f 100644 --- a/lib/log.js +++ b/lib/log.js @@ -20,7 +20,7 @@ function info() { //var ts = ts_t.format("%Y-%m-%d %H:%M:%S"); arguments["0"] = "[??INFO??] ("+ts+"): "+orig; - if(typeof global.repoproxy.loglevel == "undefined" || global.repoproxy.loglevel >= 3) { + if(typeof global.repoproxy == "undefined" || global.repoproxy.loglevel >= 3) { sendLog.apply(this, arguments); } } @@ -31,8 +31,8 @@ function debug() { //var ts = ts_t.format("%Y-%m-%d %H:%M:%S"); arguments["0"] = "[^^DEBUG^^] ("+ts+"): "+orig; - if(typeof global.repoproxy.loglevel != "undefined") { - if(global.repoproxy.loglevel >= 3) { + if(typeof global.repoproxy != "undefined") { + if(global.repoproxy.loglevel >= 4) { sendLog.apply(this, arguments); } } @@ -44,7 +44,7 @@ function warning() { //var ts = ts_t.format("%Y-%m-%d %H:%M:%S"); arguments["0"] = "[!!WARNING!!] ("+ts+"): "+orig; - if(typeof global.repoproxy.loglevel == "undefined" || global.repoproxy.loglevel >= 2) { + if(typeof global.repoproxy == "undefined" || global.repoproxy.loglevel >= 2) { sendLog.apply(this, arguments); } } @@ -55,7 +55,7 @@ function error() { //var ts = ts_t.format("%Y-%m-%d %H:%M:%S"); arguments["0"] = "[**ERROR**] ("+ts+"): "+orig; - if(typeof global.repoproxy.loglevel == "undefined" || global.repoproxy.loglevel >= 1) { + if(typeof global.repoproxy == "undefined" || global.repoproxy.loglevel >= 1) { sendLog.apply(this, arguments); } } diff --git a/lib/maintain.js b/lib/maintain.js index fe19a00..cd8ea8b 100644 --- a/lib/maintain.js +++ b/lib/maintain.js @@ -8,7 +8,14 @@ var log = require("./log.js"); function maintainCache() { // TODO i should check that im already running here and exit if i am - log.debug("Cache maintainence routine starting..."); + if(global.repoproxy.maintain==1) { + log.warning("cache maintenance routine started, but its already running"); + return; + } + + global.repoproxy.maintain = 1; + + log.info("Cache maintainence routine starting..."); for(var index in global.repoproxy.repo) { //log.debug("start cleanup in ", index); //log.debug("cleanup array ", global.repoproxy.repo[index]); @@ -32,7 +39,36 @@ function maintainCache() { break; } } - log.debug("Cache maintainence routine ended..."); + log.info("Cache maintainence routine ended..."); + + + + log.info("beginning cache trash cleanup"); + // TODO: do this bit properly, check that globals are set properly + var spawn = require('child_process').spawn; + + // TODO: be carefull we actually have a place to remove + if(typeof global.repoproxy == "undefined") { + log.error("serious issue, globals not accessible?"); + process.exit(10); + } else if(typeof global.repoproxy.cacheDir == "undefined") { + log.error("serious issue, globals not accessible (cache check)?"); + process.exit(10); + } else { + var remove = spawn("rm", ["-r", global.repoproxy.cacheDir + "/.cleanup/*"]); + remove.on("close", function(code, sig) { + log.debug("remove ended with %d, %d", code, sig); + }); + remove.stderr.on("data", function(line) { + log.debug("stderr from lazy remove: ", line.toString("utf8")); + }); + remove.stdout.on("data", function(line) { + log.debug("stdout from lazy remove: ", line.toString("ascii")); + }); + } + log.info("Trash empty"); + + global.repoproxy.maintain = 0; } exports.startTimer = function() { diff --git a/lib/repo-yum.js b/lib/repo-yum.js index cc588e1..4de23b9 100644 --- a/lib/repo-yum.js +++ b/lib/repo-yum.js @@ -35,7 +35,7 @@ function maintain(name, repoinfo, files) { var age = curtime - ctime; log.debug("age is (%d) for (%d)", age, metaAge); - if(age > metaAge) { + if(age < metaAge) { // TODO: cleanup repomd directory cache.moveToCleanup(repomddir); log.info("Sending repomd directory to trash for cleanup (%s)", repomddir); diff --git a/proxy.js b/proxy.js index 61aa8f2..da86761 100644 --- a/proxy.js +++ b/proxy.js @@ -3,14 +3,15 @@ var config = require("./lib/config.js"); var router = require("./lib/router.js"); var cache = require("./lib/cache.js"); var maintain = require("./lib/maintain.js"); +var log = require("./lib/log.js"); // first we load the config... -console.log("Loading configuration"); +log.info("Loading configuration"); config.loadConfig("./repos.conf"); // start the maintenance timer -console.log("Starting cache maintenance timer"); +log.info("Starting cache maintenance timer"); maintain.startTimer(); // next we start our main request loop diff --git a/repos.conf b/repos.conf index dfa404f..e9e9042 100644 --- a/repos.conf +++ b/repos.conf @@ -20,4 +20,4 @@ repo:fedora:yum:http://ftp.iinet.net.au/pub/fedora/linux/:7:120 repo:ubuntu:apt:http://ftp.iinet.net.au/pub/ubuntu/:1:120 # level for logging (1 = error, 2 = warning, 3=info, 4=debug); -loggerlevel:3 +loggerlevel:4 -- 1.7.0.4