summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/freeswitch_event.rb45
-rw-r--r--lib/tasks/backup.rake16
2 files changed, 51 insertions, 10 deletions
diff --git a/lib/freeswitch_event.rb b/lib/freeswitch_event.rb
index 68d9df2..89d8ea0 100644
--- a/lib/freeswitch_event.rb
+++ b/lib/freeswitch_event.rb
@@ -15,7 +15,11 @@ class FreeswitchEventSocket
return false
end
- def connect(password = DEFAULT_PASSWORD, event_host = DEFAULT_HOST, event_port = DEFAULT_PORT)
+ def connect(password = nil, event_host = nil, event_port = nil)
+ event_host = event_host || GsParameter.get('host', 'event_socket', 'client') || GsParameter.get('listen-ip', 'event_socket', 'settings') || DEFAULT_HOST
+ event_port = event_port || GsParameter.get('port', 'event_socket', 'client') || GsParameter.get('listen-port', 'event_socket', 'settings') || DEFAULT_PORT
+ password = password || GsParameter.get('password', 'event_socket', 'client') || GsParameter.get('password', 'event_socket', 'settings') || DEFAULT_PASSWORD
+
begin
@socket = TCPSocket.open(event_host, event_port)
rescue
@@ -103,8 +107,45 @@ class FreeswitchEvent
end
class FreeswitchAPI
- def self.execute(command, arguments, bgapi = false)
+ def self.api_result(result)
+ if not result
+ return nil
+ end
+
+ if result['Content-Type'] == 'api/response'
+ if result['_BODY'].blank?
+ return nil
+ elsif result['_BODY'] =~ /^\+OK/
+ return true
+ elsif result['_BODY'] =~ /^\-ERR/
+ return false
+ else
+ return result['_BODY']
+ end
+ end
+
+ return nil
+ end
+ def self.api(command, *arguments)
+ event = FreeswitchEventSocket.new()
+ if event && event.connect()
+ event.command("api #{command} #{arguments.join(' ')}")
+ result = event.result()
+ content_length = result['Content-Length'].to_i
+ while content_length > result['_BODY'].to_s.length
+ body = event.read(content_length - result['_BODY'].to_s.length)
+ if body.blank?
+ break
+ end
+ result['_BODY'] = result['_BODY'].to_s + body;
+ end
+ event.close()
+ return result
+ end
+ end
+
+ def self.execute(command, arguments, bgapi = false)
event = FreeswitchEventSocket.new()
if event && event.connect()
api = bgapi ? 'bgapi' : 'api'
diff --git a/lib/tasks/backup.rake b/lib/tasks/backup.rake
index ad4d41d..83bcfd3 100644
--- a/lib/tasks/backup.rake
+++ b/lib/tasks/backup.rake
@@ -25,32 +25,32 @@ namespace :backup do
tmp_dir = "/tmp/gs5_restore_directory"
FileUtils.rm_rf tmp_dir
FileUtils.mkdir_p tmp_dir
- system "cd #{tmp_dir} && sudo /bin/tar xzf #{restore_job.backup_file.path}"
+ system "cd #{tmp_dir} && nice -n 19 sudo /bin/tar xzf #{restore_job.backup_file.path}"
restore_directory = Dir.glob("/tmp/gs5_restore_directory/*").first
- system "cd #{restore_directory} && sudo /bin/tar xf GS5.tar && rm GS5.tar"
+ system "cd #{restore_directory} && nice -n 19 sudo /bin/tar xf GS5.tar && rm GS5.tar"
# Restore faxes
#
if File.exists?("#{restore_directory}/GS5/archives/faxes.tar.gz")
- system "cd / && sudo /bin/tar xzfP #{restore_directory}/GS5/archives/faxes.tar.gz"
+ system "cd / && nice -n 19 sudo /bin/tar xzfP #{restore_directory}/GS5/archives/faxes.tar.gz"
end
# Restore voicemails
#
if File.exists?("#{restore_directory}/GS5/archives/voicemails.tar.gz")
- system "cd / && sudo /bin/tar xzfP #{restore_directory}/GS5/archives/voicemails.tar.gz"
+ system "cd / && nice -n 19 sudo /bin/tar xzfP #{restore_directory}/GS5/archives/voicemails.tar.gz"
end
# Restore recordings
#
if File.exists?("#{restore_directory}/GS5/archives/recordings.tar.gz")
- system "cd / && sudo /bin/tar xzfP #{restore_directory}/GS5/archives/recordings.tar.gz"
+ system "cd / && nice -n 19 sudo /bin/tar xzfP #{restore_directory}/GS5/archives/recordings.tar.gz"
end
# Restore avatars
#
if File.exists?("#{restore_directory}/GS5/archives/avatars.tar.gz")
- system "cd / && sudo /bin/tar xzfP #{restore_directory}/GS5/archives/avatars.tar.gz"
+ system "cd / && nice -n 19 sudo /bin/tar xzfP #{restore_directory}/GS5/archives/avatars.tar.gz"
end
# Delete the archive tar.gz to get more air to breathe
@@ -65,11 +65,11 @@ namespace :backup do
db_user = system_odbc_configuration['gemeinschaft']['USER']
db_password = system_odbc_configuration['gemeinschaft']['PASSWORD']
- system "gunzip < #{restore_directory}/GS5/databases/MySQL/gemeinschaft.sql.gz | mysql -u #{db_user} -p#{db_password} #{database}"
+ system "nice -n 19 gunzip < #{restore_directory}/GS5/databases/MySQL/gemeinschaft.sql.gz | nice -n 19 mysql -u #{db_user} -p#{db_password} #{database}"
FileUtils.rm_rf tmp_dir
- system "cd /opt/gemeinschaft && rake db:migrate"
+ system "cd /opt/gemeinschaft && nice -n 19 rake db:migrate"
# Rebuild the thumbnails
#