diff options
Diffstat (limited to '')
-rwxr-xr-x | _.lua | 77 |
1 files changed, 34 insertions, 43 deletions
@@ -3,21 +3,41 @@ | |||
3 | 3 | ||
4 | -- Most of this _ stuff was copied from apt-panopticon. | 4 | -- Most of this _ stuff was copied from apt-panopticon. |
5 | local _ = {} | 5 | local _ = {} |
6 | |||
7 | _.version = '0.0 crap' | 6 | _.version = '0.0 crap' |
8 | 7 | ||
9 | _.D = function(s) print('DEBUG ' .. s) end | 8 | |
10 | _.I = function(s) print('INFO ' .. s) end | 9 | D = function(s) print('DEBUG ' .. s) end |
11 | _.T = function(s) print('TIMEOUT ' .. s) end | 10 | I = function(s) print('INFO ' .. s) end |
12 | _.W = function(s) print('WARNING ' .. s) end | 11 | T = function(s) print('TIMEOUT ' .. s) end |
13 | _.E = function(s) print('ERROR ' .. s) end | 12 | W = function(s) print('WARNING ' .. s) end |
14 | _.C = function(s) print('CRITICAL ' .. s) end | 13 | E = function(s) print('ERROR ' .. s) end |
15 | local D = _.D | 14 | C = function(s) print('CRITICAL ' .. s) end |
16 | local I = _.I | 15 | |
17 | local T = _.T | 16 | |
18 | local W = _.W | 17 | _.runnable = function(c) |
19 | local E = _.E | 18 | return ( 0 == __('which ' .. c):Do().status ) |
20 | local C = _.C | 19 | end |
20 | |||
21 | _.running = function(c) | ||
22 | return ( 1 ~= tonumber(__("pgrep -u $USER -cf " .. c):Do().lines[1]) ) | ||
23 | end | ||
24 | |||
25 | _.exists = function(f) | ||
26 | local h, e = io.open(f, "r") | ||
27 | if nil == h then return false else h:close(); return true end | ||
28 | end | ||
29 | |||
30 | _.killEmAll = function(all) | ||
31 | for i,l in ipairs(all) do | ||
32 | local c = 0 | ||
33 | while 0 ~= tonumber(__("pgrep -u $USER -xc " .. l):Do().lines[1]) do | ||
34 | local s = 'TERM' | ||
35 | if c > 1 then s = 'KILL'; __("sleep " .. c):Do() end | ||
36 | __("pkill -" .. s .. " -u $USER -x " .. l):log():Do() | ||
37 | c = c + 1 | ||
38 | end | ||
39 | end | ||
40 | end | ||
21 | 41 | ||
22 | 42 | ||
23 | _.readCmd = function(cmd) | 43 | _.readCmd = function(cmd) |
@@ -33,8 +53,7 @@ _.readCmd = function(cmd) | |||
33 | return result | 53 | return result |
34 | end | 54 | end |
35 | 55 | ||
36 | 56 | __ = function(c) | |
37 | _._ = function(c) | ||
38 | local exe = {status = 0, lines = {}, logging = false, showing = false, cmd = '', command = c} | 57 | local exe = {status = 0, lines = {}, logging = false, showing = false, cmd = '', command = c} |
39 | local n = 0 | 58 | local n = 0 |
40 | 59 | ||
@@ -165,33 +184,5 @@ _._ = function(c) | |||
165 | return exe | 184 | return exe |
166 | end | 185 | end |
167 | 186 | ||
168 | local __ = _._ | ||
169 | |||
170 | _.runnable = function(c) | ||
171 | return ( 0 == __('which ' .. c):Do().status ) | ||
172 | end | ||
173 | |||
174 | _.running = function(c) | ||
175 | return ( 1 ~= tonumber(__("pgrep -u $USER -cf " .. c):Do().lines[1]) ) | ||
176 | end | ||
177 | |||
178 | _.exists = function(f) | ||
179 | local h, e = io.open(f, "r") | ||
180 | if nil == h then return false else h:close(); return true end | ||
181 | end | ||
182 | |||
183 | _.killEmAll = function(all) | ||
184 | for i,l in ipairs(all) do | ||
185 | local c = 0 | ||
186 | while 0 ~= tonumber(__("pgrep -u $USER -xc " .. l):Do().lines[1]) do | ||
187 | local s = 'TERM' | ||
188 | if c > 1 then s = 'KILL'; __("sleep " .. c):Do() end | ||
189 | __("pkill -" .. s .. " -u $USER -x " .. l):log():Do() | ||
190 | c = c + 1 | ||
191 | end | ||
192 | end | ||
193 | end | ||
194 | |||
195 | |||
196 | 187 | ||
197 | return _ | 188 | return _ |