aboutsummaryrefslogtreecommitdiffstats
path: root/jackoffall
blob: 6c7cec20585a033c5ed5faa3a55fe790294d3240 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env luajit


local APT = {}


APT.readCmd = function(cmd)
    local result = {}
    local output = io.popen(cmd)
    if nil ~= output then
	for l in output:lines() do
	    table.insert(result, l)
	end
    end
    return result
end


APT.exe = function(c)
    local exe = {status = 0, result = '', log = true, cmd = c .. ' ', command = c}

    function exe:log()
	self.log = true
	return self
    end
    function exe:Nice(c)
	if nil == c then
	    self.cmd = 'ionice -c3 nice -n 19 ' .. self.cmd
	else
	    self.cmd = self.cmd .. 'ionice -c3 nice -n 19 ' .. c .. ' '
	end
	return self
    end
    function exe:timeout(c)
	-- 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.
	-- --kill-after means "send KILL after TERM fails.
	if nil == c then
	    self.cmd = 'timeout --kill-after=10.0 --foreground 42.0s ' .. self.cmd
	else
	    self.cmd = 'timeout --kill-after=10.0 --foreground ' .. c .. ' ' .. self.cmd
	end
	return self
    end
    function exe:also(c)
	if nil == c then c = '' else c = ' ' .. c end
	self.cmd = self.cmd .. ';' .. c .. ' '
	return self
    end
    function exe:And(c)
	if nil == c then c = '' else c = ' ' .. c end
	self.cmd = self.cmd .. '&&' .. c .. ' '
	return self
    end
    function exe:Or(c)
	if nil == c then c = '' end
	self.cmd = self.cmd .. '|| ' .. c .. ' '
	return self
    end
    function exe:noErr()
	self.cmd = self.cmd .. '2>/dev/null '
	return self
    end
    function exe:wait(w)
	self.cmd = self.cmd .. '&& touch ' .. w .. ' '
	return self
    end
    function exe:Do()
    --[[    "The condition expression of a control structure can return any
	    value. Both false and nil are considered false. All values different
	    from nil and false are considered true (in particular, the number 0
	    and the empty string are also true)."
	says the docs, I beg to differ.]]
	if true == self.log then D("  executing - &nbsp; <code>" .. self.cmd .. "</code>") end
	--[[ Damn os.execute()
	    Lua 5.1 says it returns "a status code, which is system-dependent"
	    Lua 5.2 says it returns true/nil, "exit"/"signal", the status code.
	    I'm getting 7168 or 0.  No idea what the fuck that is.
	local ok, rslt, status = os.execute(s)
	]]
	local f = APT.readCmd(self.cmd, 'r')
	-- The last line will be the command's returned status, collect everything else in result.
	self.status = ''	-- Otherwise the result starts with 0.
	self.result = '\n'
	for i,l in ipairs(f) do
	    self.result = self.result .. l .. "\n"
	end
	f = APT.readCmd('echo "$?"', 'r')
	for i,l in ipairs(f) do
	    self.status = tonumber(l)
	    if (137 == self.status) or (124 == self.status) then
		print("timeout killed " .. self.status .. ' ' .. self.command)
		E("timeout killed " .. self.status .. ' ' .. self.command)
	    elseif (0 ~= self.status) then
		print("status |" .. self.status .. '| ' .. self.command)
		E("status |" .. self.status .. '| ' .. self.command)
	    end
	end
	return self
    end
    function exe:fork(host)
	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
	self.cmd = '{ ' .. self.cmd .. '; } &'
	if true == self.log then D("  forking - &nbsp; <code>" .. self.cmd .. "</code>") end
	os.execute(self.cmd)
	return self
    end
    return exe
end


APT.exe("a2j_control --stop"):Do()
APT.exe("sleep 2"):Do()
APT.exe("a2j_control --exit"):Do()
APT.exe("sleep 2"):Do()
APT.exe("killall -TERM alsa_out"):Do()
APT.exe("killall -TERM alsa_in"):Do()
APT.exe("killall -TERM zita-a2j"):Do()
APT.exe("killall -TERM zita-j2a"):Do()
APT.exe("killall -TERM aseqjoy"):Do()
APT.exe("killall -TERM jack-plumbing"):Do()
APT.exe("sleep 2"):Do()
APT.exe("jack_control stop"):Do()
APT.exe("sleep 2"):Do()
APT.exe("jack_control exit"):Do()
APT.exe("sleep 2"):Do()
--APT.exe("a2j_control --stop; a2j_control --exit"):Do()
--APT.exe("sleep 2"):Do()
APT.exe("killall -TERM jmcore"):Do()
APT.exe("pkill -TERM jackdbus; pkill -TERM a2jmidid"):Do()
APT.exe("killall -TERM a2jmidid"):Do()
APT.exe("killall -KILL jackdbus"):Do()
APT.exe("sleep 2"):Do()
APT.exe("killall -KILL a2jmidid"):Do()
APT.exe("pkill -KILL jackdbus; pkill -KILL a2jmidid"):Do()
APT.exe("sleep 2"):Do()
APT.exe("killall -KILL a2jmidid"):Do()
APT.exe("killall -KILL jackdbus"):Do()
APT.exe("sleep 2"):Do()
APT.exe("killall -KILL a2jmidid"):Do()
APT.exe("killall -KILL jackdbus"):Do()
APT.exe("sleep 2"):Do()
APT.exe("pkill -KILL jackdbus; pkill -KILL a2jmidid"):Do()
APT.exe("killall -TERM qjackctl"):Do()

-- Catia is python, and no easy way to kill it.
APT.exe("ps auxw | grep python"):Do()