mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 07:29:32 +00:00
Avoid too many forks by caching hasService result
This commit is contained in:
parent
d6e78848ed
commit
2414538a2a
1 changed files with 11 additions and 3 deletions
|
|
@ -75,11 +75,19 @@ end
|
|||
--! @brief Check if a service is available into the system.
|
||||
--! @return true if service is available, false otherwise.
|
||||
function os_utils.hasService(service_name, ...)
|
||||
if not ntop.exists(NTOPNG_CONFIG_TOOL) then
|
||||
return false
|
||||
local cmd = ntopctl_cmd(service_name, "has-service", ...)
|
||||
local key = "ntopng.cache.hasService." .. cmd:gsub(" ", "_")
|
||||
local rv = ntop.getCache(key)
|
||||
|
||||
if rv == nil then
|
||||
if not ntop.exists(NTOPNG_CONFIG_TOOL) then
|
||||
return false
|
||||
end
|
||||
|
||||
local rv = os_utils.execWithOutput(cmd)
|
||||
ntop.setCache(key, rv, 60)
|
||||
end
|
||||
|
||||
local rv = os_utils.execWithOutput(ntopctl_cmd(service_name, "has-service", ...))
|
||||
return(rv == "yes\n")
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue