ahn in adhearsion-0.7.5 vs ahn in adhearsion-0.7.6

- old
+ new

@@ -1,28 +1,27 @@ #!/usr/bin/env ruby -# This is the main executable file of Adhearsion. +# This is the main executable file. -# Copyright (c) 2006 Jay Phillips +# Adhearsion, open source technology integrator +# Copyright (C) 2006,2007 Jay Phillips +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +require 'rubygems' -# Permission is hereby granted, free of charge, to any person obtaining a copy of -# this software and associated documentation files (the "Software"), to deal in -# the Software without restriction, including without limitation the rights to -# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -# of the Software, and to permit persons to whom the Software is furnished to do -# so, subject to the following conditions: - -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. - -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - usage = "Usage: ahn create /path/to/directory ahn start [daemon] [directory] ahn version ahn help|-h|--h|--help|-help @@ -31,13 +30,13 @@ ahn install helpername ahn system install systemname ahn search keyword ahn uninstall/remove helpername" -$: << File.join(File.dirname(__FILE__), 'lib') +$: << File.join(File.expand_path(File.dirname(__FILE__)), 'lib') ADHEARSION_VERSION = File.read(File.join(File.dirname(__FILE__), '.version')).strip -ARGV.unshift 'start' if ARGV.empty? # Set the default operation +ARGV.unshift 'start' if ARGV.empty? # Set the default operation require 'yaml' $HUTDOWN = [] class << $HUTDOWN @@ -101,19 +100,21 @@ Adhearsion project generated! Start your new app with "ahn start #{dest_dir_relative}" -For dial plan management, change the appropriate contexts -in your /etc/asterisk/extensions.conf file to the following: +If you wish to use Adhearsion to control Asterisk's dialplan, +change the contexts you wish to be affected in your +/etc/asterisk/extensions.conf file to the following: [your_context_name] exten => _X.,1,AGI(agi://1.2.3.4) ; This IP here -To use databases edit config/database.yml for the +To use databases, edit config/database.yml for the connection information and, optionally, config/database.rb -to change the default database object models. +to change the default database object models. To create your +tables, you may wish to use config/migration.rb. Asterisk Manager interface integration is highly recommended. Edit your /etc/asterisk/manager.conf file and enable the system *securely* with an account for this app. Reload with "asterisk -rx reload manager" and then edit the @@ -129,75 +130,90 @@ $DAEMON = false target = Dir.pwd arg = ARGV.shift - if arg =~ /daemon(ize)?/ + if arg =~ /daemon(ized)?/ $DAEMON = true arg = ARGV.shift end target = File.expand_path(arg || target) + puts %{\nStarting Adhearsion v#{ADHEARSION_VERSION} + Written by Jay Phillips of Codemecca LLC, et al. + http://adhearsion.com\n\n} + + if $DAEMON + require 'rubygems' + require 'daemons' + puts "Daemonizing now!" + Daemons.daemonize + end + Dir.chdir target adhearsion_config = File.join('config', 'adhearsion.yml') CONFIG = File.readable?(adhearsion_config) ? YAML.load_file(adhearsion_config) : {} require 'logging' register_logger StandardLogger.new(STDOUT) register_logger StandardLogger.new('logs/adhearsion.log') + - puts %{\nStarting Adhearsion v#{ADHEARSION_VERSION} - Written by Jay Phillips of Codemecca LLC, et al. - http://adhearsion.com\n\n} - %w(rubygems uri open-uri abbrev thread).each { |lib| require lib } $: << 'config' require 'adhearsion' require 'database' if CONFIG['enable_database'] require 'servlet_container' - require "constants" + require 'constants' + if CONFIG['drb'] && CONFIG['drb']['enabled'] + require 'drb_server' + DRbServerManager.start + end + # Load appropriate helpers $HELPERS = {} Contexts::Container.new.run_inside do # Start with compiled helpers - class << Object - aliens = Dir[File.join('helpers', '*.alien.*')] - aliens.each do |f| - f = File.basename f - config_file = File.join %W(config helpers #{f}.yml) - config = File.readable?(config_file) ? YAML.load_file(config_file) : {} - if config.delete('enabled') != false - require 'inline' - lang = f[f.rindex('.')+1..-1] - log "Loading helper #{f} as #{lang.upcase}" + class Object + class << self + aliens = Dir[File.join('helpers', '*.alien.*')] + aliens.each do |f| + f = File.basename f + config_file = File.join %W(config helpers #{f}.yml) + config = File.readable?(config_file) ? YAML.load_file(config_file) : {} + if config.delete('enabled') != false + require 'inline' + lang = f[f.rindex('.') + 1..-1] + log "Loading helper #{f} as #{lang.upcase}" - $HELPERS[f] = config - inline do |builder| - builder.send lang, File.read(File.join('helpers', f)) + $HELPERS[f] = config + inline do |builder| + builder.send lang, File.read(File.join('helpers', f)) + end end end end - end - # Load Ruby helpers - Dir[File.join('helpers', '*.rb')].each do |f| - name = File.basename(f)[/^[^.]+/] - config_file = File.join %W(config helpers #{name}.yml) - config = File.readable?(config_file) ? YAML.load_file(config_file) : {} - if config.delete('enabled') != false - log "Parsing helper #{name}" - $HELPERS[name] = config - eval File.read(f) + # Load Ruby helpers + Dir[File.join('helpers', '*.rb')].each do |f| + name = File.basename(f)[/^[^.]+/] + config_file = File.join %W(config helpers #{name}.yml) + config = File.readable?(config_file) ? YAML.load_file(config_file) : {} + if config.delete('enabled') != false + log "Parsing helper #{name}" + $HELPERS[name] = config + eval File.read(f) + end end end end - sc = ServletContainer.new(CONFIG['port'] || 4573) + sc = ServletContainer.new((CONFIG['port'] || 4573), (CONFIG['host'] || '0.0.0.0')) $HUTDOWN.hook { sc.shutdown } log "Dallas, we have liftoff!" sc.server.join