Module: Larynx
- Extended by:
- Callbacks
- Defined in:
- lib/larynx.rb,
lib/larynx/form.rb,
lib/larynx/fields.rb,
lib/larynx/logger.rb,
lib/larynx/prompt.rb,
lib/larynx/command.rb,
lib/larynx/session.rb,
lib/larynx/version.rb,
lib/larynx/commands.rb,
lib/larynx/response.rb,
lib/larynx/callbacks.rb,
lib/larynx/observable.rb,
lib/larynx/application.rb,
lib/larynx/call_handler.rb,
lib/larynx/restartable_timer.rb,
lib/larynx/callbacks_with_async.rb
Defined Under Namespace
Modules: Callbacks, CallbacksWithAsync, Commands, Fields, Observable
Classes: ApiCommand, AppCommand, Application, CallCommand, CallHandler, Command, Form, Logger, NoPromptCommandValue, NoPromptDefined, Prompt, Response, RestartableTimer, Session
Constant Summary
collapse
- VERSION =
'0.1.4'
Class Method Summary
collapse
Methods included from Callbacks
included
Class Method Details
.daemonize ⇒ Object
67
68
69
70
71
|
# File 'lib/larynx.rb', line 67
def daemonize
Daemonize.daemonize
Dir.chdir LARYNX_ROOT
File.open(@options[:pid_file], 'w+') {|f| f.write("#{Process.pid}\n") }
end
|
.graceful_exit ⇒ Object
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/larynx.rb', line 56
def graceful_exit
msg = "Shutting down Larynx"
$stderr.puts msg unless @options[:daemon]
LARYNX_LOGGER.info msg
EM.stop_server @em_signature
@em_signature = nil
remove_pid_file if @options[:daemonize]
exit 130
end
|
.parse_options(args = ARGV) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/larynx.rb', line 29
def parse_options(args=ARGV)
@options = {
:ip => "0.0.0.0",
:port => 8084,
:pid_file => "./larynx.pid",
:log_file => "./larynx.log"
}
opts = OptionParser.new
opts.banner = "Usage: larynx [options]"
opts.separator ''
opts.separator "Larynx is a framework to develop FreeSWITCH IVR applications in Ruby."
opts.on('-i', '--ip IP', 'Listen for connections on this IP') {|ip| @options[:ip] = ip }
opts.on('-p', '--port PORT', 'Listen on this port', Integer) {|port| @options[:port] = port }
opts.on('-d', '--daemonize', 'Run as daemon') { @options[:daemonize] = true }
opts.on('-l', '--log-file FILE', 'Defaults to /app/root/larynx.log') {|log| @options[:log_file] = log }
opts.on( '--pid-file FILE', 'Defaults to /app/root/larynx.pid') {|pid| @options[:pid_file] = pid }
opts.on('-h', '--help', 'This is it') { $stderr.puts opts; exit 0 }
opts.on('-v', '--version') { $stderr.puts "Larynx version #{Larynx::VERSION}"; exit 0 }
opts.parse!(args)
end
|
.remove_pid_file ⇒ Object
73
74
75
|
# File 'lib/larynx.rb', line 73
def remove_pid_file
File.delete @options[:pid_file]
end
|
.run ⇒ Object
101
102
103
104
105
106
107
108
|
# File 'lib/larynx.rb', line 101
def run
parse_options(ARGV)
setup_app
daemonize if @options[:daemonize]
setup_logger
trap_signals
start_server
end
|
.running? ⇒ Boolean
110
111
112
|
# File 'lib/larynx.rb', line 110
def running?
!@em_signature.nil?
end
|
.setup_app ⇒ Object
82
83
84
85
86
87
88
89
|
# File 'lib/larynx.rb', line 82
def setup_app
if ARGV[0].nil?
$stderr.puts "You must specify an application file"
exit -1
end
Object.const_set "LARYNX_ROOT", File.expand_path(File.dirname(ARGV[0]))
require File.expand_path(ARGV[0])
end
|
.setup_logger ⇒ Object
50
51
52
53
54
|
# File 'lib/larynx.rb', line 50
def setup_logger
logger = Larynx::Logger.new(@options[:log_file])
logger.level = Logger::INFO
Object.const_set "LARYNX_LOGGER", logger
end
|
.start_server ⇒ Object
91
92
93
94
95
96
97
98
99
|
# File 'lib/larynx.rb', line 91
def start_server
msg = "Larynx starting up on #{@options[:ip]}:#{@options[:port]}"
$stderr.puts msg unless @options[:daemon]
LARYNX_LOGGER.info msg
EM::run {
@em_signature = EM::start_server @options[:ip], @options[:port], Larynx::CallHandler
}
end
|
.trap_signals ⇒ Object
77
78
79
80
|
# File 'lib/larynx.rb', line 77
def trap_signals
trap('TERM') { graceful_exit }
trap('INT') { graceful_exit }
end
|