Class: WebroarCommand
- Inherits:
-
Object
- Object
- WebroarCommand
- Defined in:
- lib/webroar_command.rb
Overview
Basic WebROaR commands
Instance Method Summary collapse
-
#add(options, args) ⇒ Object
Add and start the application.
-
#clear ⇒ Object
Clear log files.
-
#initialize ⇒ WebroarCommand
constructor
A new instance of WebroarCommand.
-
#operation(args, op) ⇒ Object
Start/Stop/Restart Command.
-
#remove(args) ⇒ Object
Stop and remove the application.
Constructor Details
#initialize ⇒ WebroarCommand
Returns a new instance of WebroarCommand.
24 25 26 27 28 |
# File 'lib/webroar_command.rb', line 24 def initialize @server_status = :down @starling_status = :down @analyzer_status = :down end |
Instance Method Details
#add(options, args) ⇒ Object
Add and start the application
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/webroar_command.rb', line 78 def add(, args) return unless CheckUser.check if args.length < 2 puts "Application name is missing." return end sockFile = File.join("","tmp","webroar.sock") unless File.exist?(sockFile) puts "Either the server is not started or 'webroar.sock' file is deleted." return end # gem 'activesupport', '>= 2.3.5' # gem 'activerecord', '>= 2.3.5' # require 'active_record' $LOAD_PATH.unshift("#{File.join(ADMIN_PANEL_ROOT,'vendor', 'rails', 'activerecord', 'lib')}") $LOAD_PATH.unshift("#{File.join(ADMIN_PANEL_ROOT,'vendor', 'rails', 'activesupport', 'lib')}") require File.join(ADMIN_PANEL_ROOT,'vendor', 'rails', 'activerecord', 'lib', 'active_record') files = Dir.glob(File.join(ADMIN_PANEL_ROOT, 'app', 'models', "{app,pseudo_model,application_specification,server_specification}.rb")) files << File.join(ADMIN_PANEL_ROOT, 'config','initializers','application_constants.rb') files << File.join(ADMIN_PANEL_ROOT, 'lib','yaml_writer.rb') load_files(files) params = {:app_id => nil, :name => args[1], :host_names => nil, :baseuri => nil, :resolver => [:resolver], :path => [:path], :run_as_user => [:run_as_user], :type1 => [:type1] ? [:type1] : 'Rails', :analytics => [:analytics] ? [:analytics] : 'Disabled', :environment => [:environment] ? [:environment] : 'production', :min_worker => [:min_worker] ? [:min_worker] : MIN_WORKERS, :max_worker => [:max_worker] ? [:max_worker] : MAX_WORKERS} application_specification = ApplicationSpecification.new(params) if application_specification.save application_specification.write application_specification.errors.each_full{|msg| puts msg } reply, err_log = App.start(params[:name]) #reply = nil indicate success puts reply ? reply : "Application '#{params[:name]}' added successfully." puts "\n\e[31m" + err_log + "\e[0m" if err_log application_specification.remove if (err_log or reply) else application_specification.errors.each_full{|msg| puts msg } end end |
#clear ⇒ Object
Clear log files
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/webroar_command.rb', line 31 def clear() return unless CheckUser.check print "Clearing log files ..." log_file_pattern = File.join('','var','log','webroar','*.log') log_files = Dir.glob(log_file_pattern) log_files.each do |file| File.truncate(file, 0) if File.exists?(file) end puts " done." end |
#operation(args, op) ⇒ Object
Start/Stop/Restart Command
43 44 45 46 |
# File 'lib/webroar_command.rb', line 43 def operation(args, op) return unless CheckUser.check (args.nil? or args.length == 1) ? server_operation(op) : application_operation(args, op) end |
#remove(args) ⇒ Object
Stop and remove the application
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/webroar_command.rb', line 49 def remove(args) return unless CheckUser.check if args.length < 2 puts "Application name is missing." return end # gem 'activesupport', '>= 2.3.5' # gem 'activerecord', '>= 2.3.5' # require 'active_record' $LOAD_PATH.unshift("#{File.join(ADMIN_PANEL_ROOT,'vendor', 'rails', 'activerecord', 'lib')}") $LOAD_PATH.unshift("#{File.join(ADMIN_PANEL_ROOT,'vendor', 'rails', 'activesupport', 'lib')}") require File.join(ADMIN_PANEL_ROOT,'vendor', 'rails', 'activerecord', 'lib', 'active_record') files = Dir.glob(File.join(ADMIN_PANEL_ROOT, 'app', 'models', "{app,pseudo_model,application_specification,server_specification}.rb")) files << File.join(ADMIN_PANEL_ROOT, 'config','initializers','application_constants.rb') files << File.join(ADMIN_PANEL_ROOT, 'lib','yaml_writer.rb') load_files(files) reply, err_log = App.stop(args[1]) ApplicationSpecification::remove(args[1]) if reply.nil? puts reply ? reply : "Application '#{args[1]}' removed successfully." puts "\n\e[31m" + err_log + "\e[0m" if err_log end |