Skip to content

Instantly share code, notes, and snippets.

@moteus
Created July 26, 2016 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save moteus/c63396e14aa214aad56e6b3bc7e232ab to your computer and use it in GitHub Desktop.
Save moteus/c63396e14aa214aad56e6b3bc7e232ab to your computer and use it in GitHub Desktop.
-- File to conrol FusionPBX Lua services/monitors
-- @usage:
-- # stop `call_flow_subscribe` monitor
-- fs_cli -x "lua service flow shutdown"
-- # stop `mwi_subscribe` monitor
-- fs_cli -x "lua service mwi shutdown"
require "resources.functions.config"
local log = require "resources.functions.log".service
local file = require "resources.functions.file"
local destination = assert(argv[1], "No service name")
local command = assert(argv[2], "No command")
local function service_status(name)
local pid_file = scripts_dir .. "/run/" .. name .. ".tmp"
return not not file.exists(pid_file)
end
local known_commands = {}
known_commands.status = function()
log.noticef( 'service %s: %s', destination,
service_status(destination) and 'RUNNING' or 'STOPPED'
)
end;
known_commands.start = function()
if service_status(destination) then
log.warningf('service %s already started', destination)
return
end
--! @todo implemnt start command
log.err('Not implemted yet')
end;
known_commands.restart = function()
if not service_status(destination) then
log.warningf('service %s not started', destination)
return
end
--! @todo implemnt start command
log.err('Not implemted yet')
end;
known_commands.stop = function()
if not service_status(destination) then
log.warningf('service %s not started', destination)
return
end
log.noticef('stopping service: %s', destination)
local event = freeswitch.Event("CUSTOM", "fusion::service::" .. destination);
event:addHeader('service-command', 'stop')
event:fire()
end;
-- try handle known commands
local cmd = known_commands[command]
if cmd then return cmd() end
log.warningf('send raw command `%s` to service %s', command, destination)
-- forward command to service itself
local event = freeswitch.Event("CUSTOM", "fusion::service::" .. destination);
event:addHeader('service-command', command)
event:fire()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment