aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/apt-panopticommon.lua
diff options
context:
space:
mode:
Diffstat (limited to 'apt-panopticommon.lua')
-rw-r--r--apt-panopticommon.lua104
1 files changed, 87 insertions, 17 deletions
diff --git a/apt-panopticommon.lua b/apt-panopticommon.lua
index 0862b77..982ff21 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
4APT.rrd = require 'rrd' 4APT.rrd = require 'rrd'
5 5
6APT.version = '0.3 alpha'
7
6APT.protocols = {"ftp", "http", "https", "rsync"} 8APT.protocols = {"ftp", "http", "https", "rsync"}
7APT.tests = {'raw', 'Integrity', 'Protocol', 'Redirects', 'Updated', 'URLSanity', 'Speed'} 9APT.tests = {'raw', 'Integrity', 'Protocol', 'Redirects', 'Updated', 'URLSanity', 'Speed'}
8APT.releases = {"ascii", "beowulf", "chimaera", "ceres"} 10--APT.releases = {"jessie", "ascii", "beowulf", "chimaera", "daedalus", "ceres"}
11APT.releases = {"beowulf","chimaera", "daedalus", "excalibur", "ceres"}
9APT.subRels = {'backports', 'proposed-updates', 'security', 'updates'} 12APT.subRels = {'backports', 'proposed-updates', 'security', 'updates'}
10APT.notExist = 13APT.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",
@@ -80,7 +90,7 @@ APT.options =
80 { 90 {
81 typ = "number", 91 typ = "number",
82 help = "", 92 help = "",
83 value = 5, 93 value = 24,
84 }, 94 },
85 timeouts = 95 timeouts =
86 { 96 {
@@ -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
419end 430end
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,19 @@ local E = APT.E
482local C = APT.C 493local C = APT.C
483 494
484 495
496APT.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 -- While this does return the same things as os.execute(), it's just as useless.
505 output:close()
506 return result
507end
508
485APT.debians = {} 509APT.debians = {}
486APT.mirrors = {} 510APT.mirrors = {}
487 511
@@ -508,7 +532,7 @@ APT.tested = function(prot, test, host)
508end 532end
509 533
510APT.exe = function(c) 534APT.exe = function(c)
511 local exe = {status = 0, result = '', log = true, cmd = c .. ' '} 535 local exe = {status = 0, result = '', log = true, cmd = c .. ' ', command = c}
512 536
513 function exe:log() 537 function exe:log()
514 self.log = true 538 self.log = true
@@ -522,6 +546,16 @@ APT.exe = function(c)
522 end 546 end
523 return self 547 return self
524 end 548 end
549 function exe:timeout(c)
550 -- 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.
551 -- --kill-after means "send KILL after TERM fails.
552 if nil == c then
553 self.cmd = 'timeout --kill-after=10.0 --foreground 42.0s ' .. self.cmd
554 else
555 self.cmd = 'timeout --kill-after=10.0 --foreground ' .. c .. ' ' .. self.cmd
556 end
557 return self
558 end
525 function exe:also(c) 559 function exe:also(c)
526 if nil == c then c = '' else c = ' ' .. c end 560 if nil == c then c = '' else c = ' ' .. c end
527 self.cmd = self.cmd .. ';' .. c .. ' ' 561 self.cmd = self.cmd .. ';' .. c .. ' '
@@ -558,17 +592,51 @@ APT.exe = function(c)
558 I'm getting 7168 or 0. No idea what the fuck that is. 592 I'm getting 7168 or 0. No idea what the fuck that is.
559 local ok, rslt, status = os.execute(s) 593 local ok, rslt, status = os.execute(s)
560 ]] 594 ]]
561 local f = io.popen(self.cmd .. ' ; echo "$?"', 'r') 595
562 -- The last line will be the command's returned status, collect everything else in result. 596 local f = APT.readCmd(self.cmd, 'r')
597 -- The last line will be the command's returned status, collect everything else in result.
563 self.status = '' -- Otherwise the result starts with 0. 598 self.status = '' -- Otherwise the result starts with 0.
564 for l in f:lines() do 599 self.result = '\n'
565 self.result = self.result .. self.status .. "\n" 600 for i,l in ipairs(f) do
566 self.status = l 601 self.result = self.result .. l .. "\n"
602 end
603 f = APT.readCmd('echo "$?"', 'r')
604 for i,l in ipairs(f) do
605 self.status = tonumber(l)
606 if (137 == self.status) or (124 == self.status) then
607 print("timeout killed " .. self.status .. ' ' .. self.command)
608 E("timeout killed " .. self.status .. ' ' .. self.command)
609 elseif (0 ~= self.status) then
610 print("status |" .. self.status .. '| ' .. self.command)
611 E("status |" .. self.status .. '| ' .. self.command)
612 end
613 end
614
615--[[ While this is more reliable, it breaks stuff that's likely making assumptions that match the old way.
616TODO - fix it later.
617 local f = APT.readCmd(self.cmd .. '; echo "$?"', 'r')
618 -- The last line will be the command's returned status, collect everything else in result.
619 self.status = tonumber(f[#f])
620 f[#f] = nil
621 self.result = '\n'
622 for i,l in ipairs(f) do
623 self.result = self.result .. l .. "\n"
624 end
625 if (137 == self.status) or (124 == self.status) then
626 print("timeout killed " .. self.status .. ' ' .. self.command)
627 print('ERROR ' .. "timeout killed " .. self.status .. ' ' .. self.command)
628 elseif (nil == self.status) then
629 print("status |" .. "NIL" .. '| ' .. self.command)
630 E("status |" .. "NIL" .. '| ' .. self.command)
631 elseif (0 ~= self.status) then
632-- print("status |" .. self.status .. '| ' .. self.command)
633 E("status |" .. self.status .. '| ' .. self.command)
567 end 634 end
568 self.status = tonumber(self.status) 635]]
569 return self 636 return self
570 end 637 end
571 function exe:fork() 638 function exe:fork(host)
639 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 .. '; } &' 640 self.cmd = '{ ' .. self.cmd .. '; } &'
573 if true == self.log then D(" forking - &nbsp; <code>" .. self.cmd .. "</code>") end 641 if true == self.log then D(" forking - &nbsp; <code>" .. self.cmd .. "</code>") end
574 os.execute(self.cmd) 642 os.execute(self.cmd)
@@ -578,7 +646,9 @@ APT.exe = function(c)
578end 646end
579 647
580APT.checkExes = function (exe) 648APT.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") 649 local count = 0
650 local ps = io.popen('ps x | grep "' .. exe .. '" | grep -v " grep " | grep -v "flock -n apt-panopticon.lock " | wc -l')
651 if nil ~= ps then count = ps:read("*l") end
582 D(count .. " " .. exe .. " commands still running.") 652 D(count .. " " .. exe .. " commands still running.")
583 return tonumber(count) 653 return tonumber(count)
584end 654end