Logic Machine Forum
Stop a running script - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Stop a running script (/showthread.php?tid=2955)



Stop a running script - Trond Hoyem - 03.11.2020

Hi

I have some system-scripts that takes several minutes to run. These are only ran by pressing the run button, so I have some control over when they are running.

But sometimes it would be good to be able to stop a script that is already running for some reason. Is this possible?


RE: Stop a running script - admin - 09.11.2020

Open scripting editor and get your script id (editor?id=123). Use this script to stop a running script with a certain id.
Code:
id = 123
os.execute('pkill -f "scripting-event.lua ' .. id .. ' "')
Note that this will work only for event scripts. For resident scripts use script.disable(script_name)


RE: Stop a running script - buuuudzik - 09.11.2020

How can I get script id in script? Is it some function available or I must get it from db?


RE: Stop a running script - benanderson_475 - 09.11.2020

(09.11.2020, 07:25)admin Wrote: Open scripting editor and get your script id (editor?id=123). Use this script to stop a running script with a certain id.
Code:
id = 123
os.execute('pkill -f "scripting-event.lua ' .. id .. ' "')
Note that this will work only for event scripts. For resident scripts use script.disable(script_name)

for an event script, dose this kill all running instances for the event script?
And is it possible to check if there are running instances before using the above?


RE: Stop a running script - admin - 09.11.2020

As I've said - open the editor and you will see the id in the address bar.
   
Otherwise you will need db queries.


RE: Stop a running script - admin - 09.11.2020

Yes, this will stop all running instances. If you want to get PIDs of a certain event script, you can use this script:
Code:
id = 123
pids = io.readproc('pgrep -f "scripting-event.lua ' .. id .. ' "')
log(pids)