FreeSwitch is blocking when doing "shutdown"
Hi. I have a start-up script in lua.conf.xml for capture and log events: <configuration name="lua.conf" description="LUA Configuration"> <settings> ... <param name="startup-script" value="callcenter-log-events-mysql.lua"/> </settings> </configuration> callcenter-log-events-mysql.lua contains a loop: while true do local dbh = freeswitch.Dbh("freeswitch_data","freeswitch","freeswitch") while dbh:connected() do freeswitch.consoleLog("debug","Connected to DB.\n") while dbh:connected() do for e in (function() return conlocal:pop(1,1000) end) do freeswitch.consoleLog("debug","Event: " .. e:serialize("xml") .. "\n") if not dbh:connected() then freeswitch.consoleLog("debug",argv[0] .. ": Database disconnected\n") break end ccAction = e:getHeader("headername") end end dbh:release() end No, the problem is that when doing a shutdown command from FS_CLI, or service stop, FS does not terminate. ps xua | grep freeswitch shows the running process. I have to kill with -9 signal. I tracked that this is related to the outermost while in my script. If this script is not started at start-up, FS is not blocking on shutdown. Is there a parameter in lua.conf.xml to instruct FS to terminate any running lua scripts? Or is a way to detect this in the script and break outermost while loop? Thank you. -- Mimiko desu.
In a call it'd be generally be advisable to use 'while session:ready' instead of 'while true' Guess you need something equivalent in a startup script. I don't think you'll have a session, but just in case try session:ready anyway to see if that works. -Steve On 23 November 2012 12:29, Mimiko <vbvbrj@gmail.com> wrote:
Hi.
I have a start-up script in lua.conf.xml for capture and log events: <configuration name="lua.conf" description="LUA Configuration"> <settings> ... <param name="startup-script" value="callcenter-log-events-mysql.lua"/> </settings> </configuration>
callcenter-log-events-mysql.lua contains a loop:
while true do local dbh = freeswitch.Dbh("freeswitch_data","freeswitch","freeswitch") while dbh:connected() do freeswitch.consoleLog("debug","Connected to DB.\n") while dbh:connected() do for e in (function() return conlocal:pop(1,1000) end) do freeswitch.consoleLog("debug","Event: " .. e:serialize("xml") .. "\n") if not dbh:connected() then freeswitch.consoleLog("debug",argv[0] .. ": Database disconnected\n") break end ccAction = e:getHeader("headername") end end dbh:release() end
No, the problem is that when doing a shutdown command from FS_CLI, or service stop, FS does not terminate. ps xua | grep freeswitch shows the running process. I have to kill with -9 signal.
I tracked that this is related to the outermost while in my script. If this script is not started at start-up, FS is not blocking on shutdown.
Is there a parameter in lua.conf.xml to instruct FS to terminate any running lua scripts? Or is a way to detect this in the script and break outermost while loop?
Thank you.
-- Mimiko desu.
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com
FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com
Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.com
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
contrib has a few startup script examples git clone git://git.freeswitch.org/freeswitch-contrib.git seven/lua/gateway_report.lua trixter/scheduled_event.lua Looks like they both wrap the outermost layer in: for e in (function() return con:pop(1) end) do I guess this is what you'll need to do. -Steve On 23 November 2012 18:16, Steven Ayre <steveayre@gmail.com> wrote:
In a call it'd be generally be advisable to use 'while session:ready' instead of 'while true'
Guess you need something equivalent in a startup script.
I don't think you'll have a session, but just in case try session:ready anyway to see if that works.
-Steve
On 23 November 2012 12:29, Mimiko <vbvbrj@gmail.com> wrote:
Hi.
I have a start-up script in lua.conf.xml for capture and log events: <configuration name="lua.conf" description="LUA Configuration"> <settings> ... <param name="startup-script" value="callcenter-log-events-mysql.lua"/> </settings> </configuration>
callcenter-log-events-mysql.lua contains a loop:
while true do local dbh = freeswitch.Dbh("freeswitch_data","freeswitch","freeswitch") while dbh:connected() do freeswitch.consoleLog("debug","Connected to DB.\n") while dbh:connected() do for e in (function() return conlocal:pop(1,1000) end) do freeswitch.consoleLog("debug","Event: " .. e:serialize("xml") .. "\n") if not dbh:connected() then freeswitch.consoleLog("debug",argv[0] .. ": Database disconnected\n") break end ccAction = e:getHeader("headername") end end dbh:release() end
No, the problem is that when doing a shutdown command from FS_CLI, or service stop, FS does not terminate. ps xua | grep freeswitch shows the running process. I have to kill with -9 signal.
I tracked that this is related to the outermost while in my script. If this script is not started at start-up, FS is not blocking on shutdown.
Is there a parameter in lua.conf.xml to instruct FS to terminate any running lua scripts? Or is a way to detect this in the script and break outermost while loop?
Thank you.
-- Mimiko desu.
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com
FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com
Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.com
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
On 23.11.2012 20:16, Steven Ayre wrote:
In a call it'd be generally be advisable to use 'while session:ready' instead of 'while true'
Nope this does not work: "attempt to index global 'session' (a nil value)"
Looks like they both wrap the outermost layer in: for e in (function() return con:pop(1) end) do
Yes I know about this method, but this does not track DB going down. Or isn't using freeswitch.Dbh() connection initiation too slow? If a lot of events will come, then connection and disconnect from server will be at high rates. Why not use persistent connection? -- Mimiko desu.
freeswitch.Dbh uses the internal caching, so it does reuse persistent connections. First connect'll be a full connect but after that it'll be instant. I believe it checks the handle is still connected before returning it. Steve on iPhone On 23 Nov 2012, at 20:20, Mimiko <vbvbrj@gmail.com> wrote:
On 23.11.2012 20:16, Steven Ayre wrote:
In a call it'd be generally be advisable to use 'while session:ready' instead of 'while true'
Nope this does not work: "attempt to index global 'session' (a nil value)"
Looks like they both wrap the outermost layer in: for e in (function() return con:pop(1) end) do
Yes I know about this method, but this does not track DB going down. Or isn't using freeswitch.Dbh() connection initiation too slow? If a lot of events will come, then connection and disconnect from server will be at high rates. Why not use persistent connection?
-- Mimiko desu.
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com
FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com
Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.com
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
participants (2)
-
Mimiko
-
Steven Ayre