diff options
author | dvs1 | 2024-10-03 17:29:25 +1000 |
---|---|---|
committer | dvs1 | 2024-10-03 17:29:25 +1000 |
commit | 140e45bc021d6c868a366a11f667b026b74607d3 (patch) | |
tree | 1a3db003c06179fb0c97c2b35747bb061992911a /jackoffall | |
parent | Init bare repo. (diff) | |
download | JackOnAllDevices-140e45bc021d6c868a366a11f667b026b74607d3.zip JackOnAllDevices-140e45bc021d6c868a366a11f667b026b74607d3.tar.gz JackOnAllDevices-140e45bc021d6c868a366a11f667b026b74607d3.tar.bz2 JackOnAllDevices-140e45bc021d6c868a366a11f667b026b74607d3.tar.xz |
First commit.
Diffstat (limited to 'jackoffall')
-rwxr-xr-x | jackoffall | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/jackoffall b/jackoffall new file mode 100755 index 0000000..6c7cec2 --- /dev/null +++ b/jackoffall | |||
@@ -0,0 +1,146 @@ | |||
1 | #!/usr/bin/env luajit | ||
2 | |||
3 | |||
4 | local APT = {} | ||
5 | |||
6 | |||
7 | APT.readCmd = function(cmd) | ||
8 | local result = {} | ||
9 | local output = io.popen(cmd) | ||
10 | if nil ~= output then | ||
11 | for l in output:lines() do | ||
12 | table.insert(result, l) | ||
13 | end | ||
14 | end | ||
15 | return result | ||
16 | end | ||
17 | |||
18 | |||
19 | APT.exe = function(c) | ||
20 | local exe = {status = 0, result = '', log = true, cmd = c .. ' ', command = c} | ||
21 | |||
22 | function exe:log() | ||
23 | self.log = true | ||
24 | return self | ||
25 | end | ||
26 | function exe:Nice(c) | ||
27 | if nil == c then | ||
28 | self.cmd = 'ionice -c3 nice -n 19 ' .. self.cmd | ||
29 | else | ||
30 | self.cmd = self.cmd .. 'ionice -c3 nice -n 19 ' .. c .. ' ' | ||
31 | end | ||
32 | return self | ||
33 | end | ||
34 | function exe:timeout(c) | ||
35 | -- 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. | ||
36 | -- --kill-after means "send KILL after TERM fails. | ||
37 | if nil == c then | ||
38 | self.cmd = 'timeout --kill-after=10.0 --foreground 42.0s ' .. self.cmd | ||
39 | else | ||
40 | self.cmd = 'timeout --kill-after=10.0 --foreground ' .. c .. ' ' .. self.cmd | ||
41 | end | ||
42 | return self | ||
43 | end | ||
44 | function exe:also(c) | ||
45 | if nil == c then c = '' else c = ' ' .. c end | ||
46 | self.cmd = self.cmd .. ';' .. c .. ' ' | ||
47 | return self | ||
48 | end | ||
49 | function exe:And(c) | ||
50 | if nil == c then c = '' else c = ' ' .. c end | ||
51 | self.cmd = self.cmd .. '&&' .. c .. ' ' | ||
52 | return self | ||
53 | end | ||
54 | function exe:Or(c) | ||
55 | if nil == c then c = '' end | ||
56 | self.cmd = self.cmd .. '|| ' .. c .. ' ' | ||
57 | return self | ||
58 | end | ||
59 | function exe:noErr() | ||
60 | self.cmd = self.cmd .. '2>/dev/null ' | ||
61 | return self | ||
62 | end | ||
63 | function exe:wait(w) | ||
64 | self.cmd = self.cmd .. '&& touch ' .. w .. ' ' | ||
65 | return self | ||
66 | end | ||
67 | function exe:Do() | ||
68 | --[[ "The condition expression of a control structure can return any | ||
69 | value. Both false and nil are considered false. All values different | ||
70 | from nil and false are considered true (in particular, the number 0 | ||
71 | and the empty string are also true)." | ||
72 | says the docs, I beg to differ.]] | ||
73 | if true == self.log then D(" executing - <code>" .. self.cmd .. "</code>") end | ||
74 | --[[ Damn os.execute() | ||
75 | Lua 5.1 says it returns "a status code, which is system-dependent" | ||
76 | Lua 5.2 says it returns true/nil, "exit"/"signal", the status code. | ||
77 | I'm getting 7168 or 0. No idea what the fuck that is. | ||
78 | local ok, rslt, status = os.execute(s) | ||
79 | ]] | ||
80 | local f = APT.readCmd(self.cmd, 'r') | ||
81 | -- The last line will be the command's returned status, collect everything else in result. | ||
82 | self.status = '' -- Otherwise the result starts with 0. | ||
83 | self.result = '\n' | ||
84 | for i,l in ipairs(f) do | ||
85 | self.result = self.result .. l .. "\n" | ||
86 | end | ||
87 | f = APT.readCmd('echo "$?"', 'r') | ||
88 | for i,l in ipairs(f) do | ||
89 | self.status = tonumber(l) | ||
90 | if (137 == self.status) or (124 == self.status) then | ||
91 | print("timeout killed " .. self.status .. ' ' .. self.command) | ||
92 | E("timeout killed " .. self.status .. ' ' .. self.command) | ||
93 | elseif (0 ~= self.status) then | ||
94 | print("status |" .. self.status .. '| ' .. self.command) | ||
95 | E("status |" .. self.status .. '| ' .. self.command) | ||
96 | end | ||
97 | end | ||
98 | return self | ||
99 | end | ||
100 | function exe:fork(host) | ||
101 | 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 | ||
102 | self.cmd = '{ ' .. self.cmd .. '; } &' | ||
103 | if true == self.log then D(" forking - <code>" .. self.cmd .. "</code>") end | ||
104 | os.execute(self.cmd) | ||
105 | return self | ||
106 | end | ||
107 | return exe | ||
108 | end | ||
109 | |||
110 | |||
111 | APT.exe("a2j_control --stop"):Do() | ||
112 | APT.exe("sleep 2"):Do() | ||
113 | APT.exe("a2j_control --exit"):Do() | ||
114 | APT.exe("sleep 2"):Do() | ||
115 | APT.exe("killall -TERM alsa_out"):Do() | ||
116 | APT.exe("killall -TERM alsa_in"):Do() | ||
117 | APT.exe("killall -TERM zita-a2j"):Do() | ||
118 | APT.exe("killall -TERM zita-j2a"):Do() | ||
119 | APT.exe("killall -TERM aseqjoy"):Do() | ||
120 | APT.exe("killall -TERM jack-plumbing"):Do() | ||
121 | APT.exe("sleep 2"):Do() | ||
122 | APT.exe("jack_control stop"):Do() | ||
123 | APT.exe("sleep 2"):Do() | ||
124 | APT.exe("jack_control exit"):Do() | ||
125 | APT.exe("sleep 2"):Do() | ||
126 | --APT.exe("a2j_control --stop; a2j_control --exit"):Do() | ||
127 | --APT.exe("sleep 2"):Do() | ||
128 | APT.exe("killall -TERM jmcore"):Do() | ||
129 | APT.exe("pkill -TERM jackdbus; pkill -TERM a2jmidid"):Do() | ||
130 | APT.exe("killall -TERM a2jmidid"):Do() | ||
131 | APT.exe("killall -KILL jackdbus"):Do() | ||
132 | APT.exe("sleep 2"):Do() | ||
133 | APT.exe("killall -KILL a2jmidid"):Do() | ||
134 | APT.exe("pkill -KILL jackdbus; pkill -KILL a2jmidid"):Do() | ||
135 | APT.exe("sleep 2"):Do() | ||
136 | APT.exe("killall -KILL a2jmidid"):Do() | ||
137 | APT.exe("killall -KILL jackdbus"):Do() | ||
138 | APT.exe("sleep 2"):Do() | ||
139 | APT.exe("killall -KILL a2jmidid"):Do() | ||
140 | APT.exe("killall -KILL jackdbus"):Do() | ||
141 | APT.exe("sleep 2"):Do() | ||
142 | APT.exe("pkill -KILL jackdbus; pkill -KILL a2jmidid"):Do() | ||
143 | APT.exe("killall -TERM qjackctl"):Do() | ||
144 | |||
145 | -- Catia is python, and no easy way to kill it. | ||
146 | APT.exe("ps auxw | grep python"):Do() | ||