diff options
Diffstat (limited to 'apt-panopticommon.lua')
-rw-r--r-- | apt-panopticommon.lua | 75 |
1 files changed, 60 insertions, 15 deletions
diff --git a/apt-panopticommon.lua b/apt-panopticommon.lua index 0862b77..e31c22f 100644 --- a/apt-panopticommon.lua +++ b/apt-panopticommon.lua | |||
@@ -3,14 +3,18 @@ local APT = {} | |||
3 | -- https://oss.oetiker.ch/rrdtool/prog/rrdlua.en.html | 3 | -- https://oss.oetiker.ch/rrdtool/prog/rrdlua.en.html |
4 | APT.rrd = require 'rrd' | 4 | APT.rrd = require 'rrd' |
5 | 5 | ||
6 | APT.version = '0.3 alpha' | ||
7 | |||
6 | APT.protocols = {"ftp", "http", "https", "rsync"} | 8 | APT.protocols = {"ftp", "http", "https", "rsync"} |
7 | APT.tests = {'raw', 'Integrity', 'Protocol', 'Redirects', 'Updated', 'URLSanity', 'Speed'} | 9 | APT.tests = {'raw', 'Integrity', 'Protocol', 'Redirects', 'Updated', 'URLSanity', 'Speed'} |
8 | APT.releases = {"ascii", "beowulf", "chimaera", "ceres"} | 10 | --APT.releases = {"jessie", "ascii", "beowulf", "chimaera", "daedalus", "ceres"} |
11 | APT.releases = {"beowulf","chimaera", "daedalus", "excalibur", "ceres"} | ||
9 | APT.subRels = {'backports', 'proposed-updates', 'security', 'updates'} | 12 | APT.subRels = {'backports', 'proposed-updates', 'security', 'updates'} |
10 | APT.notExist = | 13 | APT.notExist = |
11 | { | 14 | { |
12 | 'chimaera-backports', | 15 | 'excalibur-backports', |
13 | 'chimaera-security', | 16 | 'excalibur-security', |
17 | 'excalibur-updates', | ||
14 | 'ceres-backports', -- These will never exist, it's our code name for the testing suite. | 18 | 'ceres-backports', -- These will never exist, it's our code name for the testing suite. |
15 | 'ceres-proposed-updates', | 19 | 'ceres-proposed-updates', |
16 | 'ceres-updates', | 20 | 'ceres-updates', |
@@ -50,6 +54,12 @@ APT.options = | |||
50 | help = "The round robin DNS name.", | 54 | help = "The round robin DNS name.", |
51 | value = "deb.devuan.org", | 55 | value = "deb.devuan.org", |
52 | }, | 56 | }, |
57 | roundRobinCname = | ||
58 | { | ||
59 | typ = "string", | ||
60 | help = "The round robin DNS name.", | ||
61 | value = "deb.rr.devuan.org", | ||
62 | }, | ||
53 | tests = | 63 | tests = |
54 | { | 64 | { |
55 | typ = "table", | 65 | typ = "table", |
@@ -125,7 +135,7 @@ APT.parseArgs = function(args) | |||
125 | local arg = {} | 135 | local arg = {} |
126 | local sendArgs = "" | 136 | local sendArgs = "" |
127 | -- A special test to disable IPv6 tests if IPv6 isn't available. | 137 | -- A special test to disable IPv6 tests if IPv6 isn't available. |
128 | if 1 == APT.exe('ip -6 addr | grep inet6 | grep " global"'):Do().status then | 138 | if 1 == APT.exe('ip -6 addr | grep inet6 | grep " global"'):timeout():Do().status then |
129 | table.insert(args, '--tests=-IPv6') | 139 | table.insert(args, '--tests=-IPv6') |
130 | end | 140 | end |
131 | if 0 ~= #(args) then | 141 | if 0 ~= #(args) then |
@@ -139,7 +149,7 @@ APT.parseArgs = function(args) | |||
139 | end | 149 | end |
140 | os.exit() | 150 | os.exit() |
141 | elseif "--version" == a then | 151 | elseif "--version" == a then |
142 | print("apt-panopticon version 0.2 alpha") | 152 | print("apt-panopticon version " .. APT.version) |
143 | os.exit() | 153 | os.exit() |
144 | elseif "-v" == a then | 154 | elseif "-v" == a then |
145 | APT.verbosity = APT.verbosity + 1 | 155 | APT.verbosity = APT.verbosity + 1 |
@@ -398,7 +408,7 @@ APT.logOpen = function(host, a2, a3) | |||
398 | local name = APT.logName(host, a2, a3)[1] | 408 | local name = APT.logName(host, a2, a3)[1] |
399 | if APT.checkFile(name) then return false end | 409 | if APT.checkFile(name) then return false end |
400 | APT.logFile, e = io.open(name, "a+") | 410 | APT.logFile, e = io.open(name, "a+") |
401 | if nil == APT.logFile then C('opening log file (' .. name .. ') - ' .. e); return false end | 411 | if nil == APT.logFile then print('CRITICAL - opening log file (' .. name .. ') - ' .. e); return false end |
402 | if nil ~= APT.logFile then | 412 | if nil ~= APT.logFile then |
403 | APT.logFile:write("<html><head>\n") | 413 | APT.logFile:write("<html><head>\n") |
404 | APT.logFile:write("</head><body bgcolor='black' text='white' alink='red' link='aqua' vlink='fuchsia'>\n") | 414 | APT.logFile:write("</head><body bgcolor='black' text='white' alink='red' link='aqua' vlink='fuchsia'>\n") |
@@ -415,6 +425,7 @@ APT.logPost = function() | |||
415 | if nil ~= APT.logFile then | 425 | if nil ~= APT.logFile then |
416 | APT.logFile:write("</body></html> \n") | 426 | APT.logFile:write("</body></html> \n") |
417 | APT.logFile:close() | 427 | APT.logFile:close() |
428 | APT.logFile = nil | ||
418 | end | 429 | end |
419 | end | 430 | end |
420 | 431 | ||
@@ -455,7 +466,7 @@ local log = function(v, t, s, prot, test, host) | |||
455 | if nil ~= APT.logFile then | 466 | if nil ~= APT.logFile then |
456 | if APT.html then | 467 | if APT.html then |
457 | local colour = "white" | 468 | local colour = "white" |
458 | if -1 == v then colour = "fuchsia" end -- CRITICAL | 469 | if -1 == v then colour = "fuchsia"; print(t .. " " .. s) end -- CRITICAL |
459 | if 0 == v then colour = "red " end -- ERROR | 470 | if 0 == v then colour = "red " end -- ERROR |
460 | if 1 == v then colour = "yellow " end -- WARNING | 471 | if 1 == v then colour = "yellow " end -- WARNING |
461 | if 2 == v then colour = "blue " end -- TIMEOUT | 472 | if 2 == v then colour = "blue " end -- TIMEOUT |
@@ -482,6 +493,17 @@ local E = APT.E | |||
482 | local C = APT.C | 493 | local C = APT.C |
483 | 494 | ||
484 | 495 | ||
496 | APT.readCmd = function(cmd) | ||
497 | local result = {} | ||
498 | local output = io.popen(cmd) | ||
499 | if nil ~= output then | ||
500 | for l in output:lines() do | ||
501 | table.insert(result, l) | ||
502 | end | ||
503 | end | ||
504 | return result | ||
505 | end | ||
506 | |||
485 | APT.debians = {} | 507 | APT.debians = {} |
486 | APT.mirrors = {} | 508 | APT.mirrors = {} |
487 | 509 | ||
@@ -508,7 +530,7 @@ APT.tested = function(prot, test, host) | |||
508 | end | 530 | end |
509 | 531 | ||
510 | APT.exe = function(c) | 532 | APT.exe = function(c) |
511 | local exe = {status = 0, result = '', log = true, cmd = c .. ' '} | 533 | local exe = {status = 0, result = '', log = true, cmd = c .. ' ', command = c} |
512 | 534 | ||
513 | function exe:log() | 535 | function exe:log() |
514 | self.log = true | 536 | self.log = true |
@@ -522,6 +544,16 @@ APT.exe = function(c) | |||
522 | end | 544 | end |
523 | return self | 545 | return self |
524 | end | 546 | end |
547 | function exe:timeout(c) | ||
548 | -- timeout returns a status of - command status if --preserve-status; "128+9" (actually 137) if --kill-after ends up being done; 124 if it had to TERM; command status if all went well. | ||
549 | -- --kill-after means "send KILL after TERM fails. | ||
550 | if nil == c then | ||
551 | self.cmd = 'timeout --kill-after=10.0 --foreground 42.0s ' .. self.cmd | ||
552 | else | ||
553 | self.cmd = 'timeout --kill-after=10.0 --foreground ' .. c .. ' ' .. self.cmd | ||
554 | end | ||
555 | return self | ||
556 | end | ||
525 | function exe:also(c) | 557 | function exe:also(c) |
526 | if nil == c then c = '' else c = ' ' .. c end | 558 | if nil == c then c = '' else c = ' ' .. c end |
527 | self.cmd = self.cmd .. ';' .. c .. ' ' | 559 | self.cmd = self.cmd .. ';' .. c .. ' ' |
@@ -558,17 +590,28 @@ APT.exe = function(c) | |||
558 | I'm getting 7168 or 0. No idea what the fuck that is. | 590 | I'm getting 7168 or 0. No idea what the fuck that is. |
559 | local ok, rslt, status = os.execute(s) | 591 | local ok, rslt, status = os.execute(s) |
560 | ]] | 592 | ]] |
561 | local f = io.popen(self.cmd .. ' ; echo "$?"', 'r') | 593 | local f = APT.readCmd(self.cmd, 'r') |
562 | -- The last line will be the command's returned status, collect everything else in result. | 594 | -- The last line will be the command's returned status, collect everything else in result. |
563 | self.status = '' -- Otherwise the result starts with 0. | 595 | self.status = '' -- Otherwise the result starts with 0. |
564 | for l in f:lines() do | 596 | self.result = '\n' |
565 | self.result = self.result .. self.status .. "\n" | 597 | for i,l in ipairs(f) do |
566 | self.status = l | 598 | self.result = self.result .. l .. "\n" |
599 | end | ||
600 | f = APT.readCmd('echo "$?"', 'r') | ||
601 | for i,l in ipairs(f) do | ||
602 | self.status = tonumber(l) | ||
603 | if (137 == self.status) or (124 == self.status) then | ||
604 | print("timeout killed " .. self.status .. ' ' .. self.command) | ||
605 | E("timeout killed " .. self.status .. ' ' .. self.command) | ||
606 | elseif (0 ~= self.status) then | ||
607 | print("status |" .. self.status .. '| ' .. self.command) | ||
608 | E("status |" .. self.status .. '| ' .. self.command) | ||
609 | end | ||
567 | end | 610 | end |
568 | self.status = tonumber(self.status) | ||
569 | return self | 611 | return self |
570 | end | 612 | end |
571 | function exe:fork() | 613 | function exe:fork(host) |
614 | if nil ~= host then self.cmd = self.cmd .. '; r=$?; if [ $r -ge 124 ]; then echo "$r ' .. host .. ' failed forked command ' .. string.gsub(self.cmd, '"', "'") .. '"; fi' end | ||
572 | self.cmd = '{ ' .. self.cmd .. '; } &' | 615 | self.cmd = '{ ' .. self.cmd .. '; } &' |
573 | if true == self.log then D(" forking - <code>" .. self.cmd .. "</code>") end | 616 | if true == self.log then D(" forking - <code>" .. self.cmd .. "</code>") end |
574 | os.execute(self.cmd) | 617 | os.execute(self.cmd) |
@@ -578,7 +621,9 @@ APT.exe = function(c) | |||
578 | end | 621 | end |
579 | 622 | ||
580 | APT.checkExes = function (exe) | 623 | APT.checkExes = function (exe) |
581 | local count = io.popen('ps x | grep "' .. exe .. '" | grep -v " grep " | grep -v "flock -n apt-panopticon.lock " | wc -l'):read("*l") | 624 | local count = 0 |
625 | local ps = io.popen('ps x | grep "' .. exe .. '" | grep -v " grep " | grep -v "flock -n apt-panopticon.lock " | wc -l') | ||
626 | if nil ~= ps then count = ps:read("*l") end | ||
582 | D(count .. " " .. exe .. " commands still running.") | 627 | D(count .. " " .. exe .. " commands still running.") |
583 | return tonumber(count) | 628 | return tonumber(count) |
584 | end | 629 | end |