Update file_cache.lua (#6507)
* Update file_cache.lua Updated file_cache.lua to use default settings for compatibility with the removal of config.lua/local.lua. Also refactored some code for readability/nesting * reload remote server list on cache clear
This commit is contained in:
parent
a83982ea1b
commit
0719510ab5
|
|
@ -1,6 +1,7 @@
|
||||||
--description
|
--description
|
||||||
--monitor custom memcache event and clear memcache on remote servers
|
--monitor custom cache event and clear cache on remote servers
|
||||||
--protect xmlrpc using a firewall on the server to limit access by ip address
|
--protect xmlrpc using a firewall on the server to limit access by ip address
|
||||||
|
--further protect it by configuring ssl for xmlrpc on the remote server
|
||||||
|
|
||||||
--dependencies
|
--dependencies
|
||||||
--install mod_curl freeswitch module
|
--install mod_curl freeswitch module
|
||||||
|
|
@ -9,33 +10,29 @@
|
||||||
--open port xmlrpc port for other master server IP addresses
|
--open port xmlrpc port for other master server IP addresses
|
||||||
--change the password for xmlrpc in system -> settings
|
--change the password for xmlrpc in system -> settings
|
||||||
--conf/autoload_configs/lua.conf.xml
|
--conf/autoload_configs/lua.conf.xml
|
||||||
-- <param name="startup-script" value="app/server/resources/memcache.lua"/>
|
-- <param name="startup-script" value="app/server/resources/file_cache.lua"/>
|
||||||
--iptables
|
--iptables
|
||||||
-- /sbin/iptables -I INPUT -j ACCEPT -p tcp --dport 8080 -s x.x.x.x/32
|
-- /sbin/iptables -I INPUT -j ACCEPT -p tcp --dport 8080 -s x.x.x.x/32
|
||||||
-- ubuntu: service iptables-persistent save
|
-- ubuntu: service iptables-persistent save
|
||||||
|
|
||||||
--define the servers running freeswitch do not include local
|
--define the servers running freeswitch do not include local
|
||||||
--[[
|
--[[
|
||||||
#put this in local.lua
|
#put this in default settings once for each server. Order doesn't matter.
|
||||||
servers = {}
|
Category: cache
|
||||||
x = 0;
|
Subcategory: remote_servers
|
||||||
servers[x] = {}
|
Type: array
|
||||||
servers[x]['method'] = "curl";
|
value: http://user:password@server_ip:8080
|
||||||
servers[x]['username'] = "freeswitch";
|
|
||||||
servers[x]['password'] = "freeswitch";
|
|
||||||
servers[x]['hostname'] = "x.x.x.x";
|
|
||||||
servers[x]['port'] = "8080";
|
|
||||||
x = x + 1;
|
|
||||||
servers[x] = {}
|
|
||||||
servers[x]['method'] = "curl";
|
|
||||||
servers[x]['username'] = "freeswitch";
|
|
||||||
servers[x]['password'] = "freeswitch";
|
|
||||||
servers[x]['hostname'] = "x.x.x.x";
|
|
||||||
servers[x]['port'] = "8080";
|
|
||||||
]]
|
]]
|
||||||
|
|
||||||
--includes config.lua which will include local.lua if it exists
|
--includes config.lua which will include local.lua if it exists
|
||||||
require "resources.functions.config"
|
require "resources.functions.config"
|
||||||
|
local Database = require "resources.functions.database";
|
||||||
|
local Settings = require "resources.functions.lazy_settings";
|
||||||
|
|
||||||
|
local db = dbh or Database.new('system');
|
||||||
|
local settings = Settings.new(db, domain_name, domain_uuid)
|
||||||
|
|
||||||
|
local server_list = settings:get('cache', 'remote_servers', 'array')
|
||||||
|
|
||||||
--subscribe to the events
|
--subscribe to the events
|
||||||
--events = freeswitch.EventConsumer("all");
|
--events = freeswitch.EventConsumer("all");
|
||||||
|
|
@ -46,6 +43,7 @@
|
||||||
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
|
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--prepare the api object
|
--prepare the api object
|
||||||
api = freeswitch.API();
|
api = freeswitch.API();
|
||||||
|
|
||||||
|
|
@ -61,31 +59,47 @@
|
||||||
api_command = trim(api_command);
|
api_command = trim(api_command);
|
||||||
freeswitch.consoleLog("NOTICE","api_command: "..api_command .. "\n");
|
freeswitch.consoleLog("NOTICE","api_command: "..api_command .. "\n");
|
||||||
end
|
end
|
||||||
if (api_command == "cache") then
|
|
||||||
|
|
||||||
|
--check if cache clear command
|
||||||
|
if (api_command ~= "cache") then
|
||||||
|
goto continue
|
||||||
|
end
|
||||||
|
|
||||||
cache_updated = false;
|
cache_updated = false;
|
||||||
local api_command_argument = event:getHeader("API-Command-Argument");
|
local api_command_argument = event:getHeader("API-Command-Argument");
|
||||||
if (api_command_argument ~= nil) then
|
if (api_command_argument ~= nil) then
|
||||||
api_command_argument = trim(api_command_argument);
|
api_command_argument = trim(api_command_argument);
|
||||||
end
|
end
|
||||||
if (api_command_argument ~= nil) then
|
if (api_command_argument == nil) then
|
||||||
|
goto continue
|
||||||
|
end
|
||||||
if (api_command_argument == "flush") then
|
if (api_command_argument == "flush") then
|
||||||
cache_updated = true
|
cache_updated = true
|
||||||
end
|
end
|
||||||
if (string.sub(api_command_argument, 0, 6) == "delete") then
|
if (string.sub(api_command_argument, 0, 6) == "delete") then
|
||||||
cache_updated = true
|
cache_updated = true
|
||||||
end
|
end
|
||||||
if (cache_updated) then
|
if (not cache_updated) then
|
||||||
for key,row in pairs(servers) do
|
goto continue
|
||||||
if (row.method == "curl") then
|
end
|
||||||
|
|
||||||
|
--update the server_list
|
||||||
|
server_list = settings:get('cache', 'remote_servers', 'array')
|
||||||
|
|
||||||
|
--check that there is work to do
|
||||||
|
if (server_list == nil) then
|
||||||
|
freeswitch.consoleLog("NOTICE","file_cache.lua: Script loaded but no servers configured\n");
|
||||||
|
goto continue
|
||||||
|
end
|
||||||
|
|
||||||
|
--send the API commands
|
||||||
|
for _, server in ipairs(server_list) do
|
||||||
api_command_argument = api_command_argument:gsub(" ", "%%20");
|
api_command_argument = api_command_argument:gsub(" ", "%%20");
|
||||||
url = [[http://]]..row.username..[[:]]..row.password..[[@]]..row.hostname..[[:]]..row.port..[[/webapi/luarun?app/servers/resources/clear_cache.lua%20]]..api_command_argument;
|
url = server..[[/webapi/luarun?app/servers/resources/clear_cache.lua%20]]..api_command_argument;
|
||||||
api = freeswitch.API();
|
api = freeswitch.API();
|
||||||
get_response = api:execute("curl", url);
|
get_response = api:execute("curl", url);
|
||||||
freeswitch.consoleLog("INFO", "[notice] curl ".. url .. " \n");
|
freeswitch.consoleLog("INFO", "[notice] curl ".. url .. " \n");
|
||||||
end
|
end
|
||||||
end
|
::continue::
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue