Class: Webroar::Command::WebroarCommand
- Inherits:
-
Object
- Object
- Webroar::Command::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.
23 24 25 26 27 |
# File 'lib/webroar_command.rb', line 23 def initialize @server_status = :down @starling_status = :down @analyzer_status = :down end |
Instance Method Details
#add(options, args) ⇒ Object
Add and start the application
76 77 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 133 134 135 136 137 |
# File 'lib/webroar_command.rb', line 76 def add(, args) return unless User.permitted? return unless server_started? rails_app = false rack_app = false if File.exists?(File.join(Dir.getwd, "config", "environment.rb")) rails_app = true elsif File.exists?(File.join(Dir.getwd, "config.ru")) rack_app = true end if args.length < 2 and rails_app == false and rack_app == false puts "Application name is missing." return end load_models args[1] = Dir.pwd.match(/[^\/]*$/).to_s if(args[1].nil? and (rails_app or rack_app )) [:path] = Dir.pwd if([:path].nil? and (rails_app or rack_app )) [:resolver] = ("/" << args[1].gsub(/[^a-zA-Z0-9_\-.~]/,'_').downcase) if([:resolver].nil? and (rails_app or rack_app )) [:type1] = "Rack" if ([:type1].nil? and rack_app) [:run_as_user] = Etc.getpwuid(File.stat(File.join(Dir.getwd, "config", "environment.rb")).uid).name if([:run_as_user].nil? and rails_app) [:run_as_user] = Etc.getpwuid(File.stat(File.join(Dir.getwd, "config.ru")).uid).name if([:run_as_user].nil? and rack_app) if(![:min_worker] or ![:max_worker]) info = YAML::load_file(CONFIG_FILE_PATH) if info [:min_worker] = info['Server Specification']['min_worker'].to_i unless [:min_worker] [:max_worker] = info['Server Specification']['max_worker'].to_i unless [:max_worker] end end 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.to_a.each{|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.to_a.each{|msg| puts msg } end end |
#clear ⇒ Object
Clear log files
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/webroar_command.rb', line 30 def clear() return unless User.permitted? 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
42 43 44 45 |
# File 'lib/webroar_command.rb', line 42 def operation(args, op) return unless User.permitted? (args.nil? or args.length == 1) ? server_operation(op) : application_operation(args, op) end |
#remove(args) ⇒ Object
Stop and remove the application
48 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 |
# File 'lib/webroar_command.rb', line 48 def remove(args) return unless User.permitted? return unless server_started? rails_app = false rack_app =false if args.length < 2 if File.exists?(File.join(Dir.getwd, "config", "environment.rb")) rails_app = true elsif File.exists?(File.join(Dir.getwd, "config.ru")) rack_app = true else puts "Application name is missing." return end end load_models args[1] = Dir.pwd.match(/[^\/]*$/).to_s if(args[1].nil? and (rails_app or rack_app )) 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 |