From 309c2eec6168eec24d98a09bfda3aa77497bf798 Mon Sep 17 00:00:00 2001 From: dvs1 Date: Sat, 19 Oct 2024 13:47:14 +1000 Subject: Make stop less crude. --- README.md | 2 +- aataaj.lua | 49 ++++++++++++++++++++++--------------------------- how_it_works.md | 2 +- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 47d1ba7..e645276 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ joysticks it finds as MIDI controllers. So any ALSA application gets routed thr JACK. This is very rough for now, only just started writing it. The stop -command is particularly crude and violent, lots of killall. +command is particularly crude and violent, lots of pkill. Since it isn't a package yet, some setup is needed. diff --git a/aataaj.lua b/aataaj.lua index 6315982..44ccd5d 100755 --- a/aataaj.lua +++ b/aataaj.lua @@ -24,7 +24,7 @@ joysticks it finds as MIDI controllers. So any ALSA application gets routed thr JACK. This is very rough for now, only just started writing it. The stop -command is particularly crude and violent, lots of killall. +command is particularly crude and violent, lots of pkill. Since it isn't a package yet, some setup is needed. @@ -190,6 +190,19 @@ APT.exe = function(c) return exe end +APT.killEmAll = function(all) + for i,l in ipairs(all) do + local c = 0 + while 0 ~= tonumber(APT.exe("pgrep -u $USER -xc " .. l):Do().result) do + local s = 'TERM' + if c > 0 then s = 'KILL' end + print( "pkill -" .. s .. " -u $USER -x " .. l) + APT.exe("pkill -" .. s .. " -u $USER -x " .. l):Do() + c = c + 1 + end + end +end + local args = {...} @@ -200,17 +213,12 @@ if 0 ~= #args then if 'start' == args[1] then elseif 'stop' == args[1] then - APT.exe("killall -TERM qsynth"):Do() + APT.killEmAll{'qsynth'} 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.killEmAll{'alsa_in', 'alsa_out', 'zita-a2j', 'zita-j2a', 'aseqjoy', 'jack-plumbing'} APT.exe("sleep 2"):Do() APT.exe("jack_control stop"):Do() APT.exe("sleep 2"):Do() @@ -218,25 +226,12 @@ if 0 ~= #args then 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() - + APT.killEmAll{'jmcore', 'qjackctl'} -- Catia is python, and no easy way to kill it. - APT.exe("ps auxw | grep python"):Do() + -- Also it keeps jackdbus alive, no matter how hard you kill it. + APT.exe("pkill -TERM -u $USER -f catia"):Do() + APT.exe("sleep 2"):Do() + APT.killEmAll{'jackdbus', 'a2jmidid'} return(0) elseif 'JACK' == args[1] then elseif 'restart' == args[1] then args[1] = 'start' @@ -564,5 +559,5 @@ elseif 'JACK' == args[1] then print('Stop our jack-plumbing, eventually.') APT.exe('sleep 4'):Do() - APT.exe("killall -TERM jack-plumbing"):Do() + APT.killEmAll("jack-plumbing"):Do() end diff --git a/how_it_works.md b/how_it_works.md index 606ecdf..847e06a 100644 --- a/how_it_works.md +++ b/how_it_works.md @@ -44,7 +44,7 @@ Then comes the argument handling. Handles the usual init script arguments, plus a couple more. Some are just aliases for "start", for now. -"stop" is very crude and violent, mostly just killall. +"stop" is very crude and violent, mostly just pkill. A short bit where you can change some options. -- cgit v1.1