Class: Webroar::Command::Installer

Inherits:
Object
  • Object
show all
Defined in:
lib/installer.rb

Constant Summary collapse

CONFIG_HEADER =
%{
######################################################################################
#                             WebROaR Configuration file
######################################################################################

######################################################################################
# Configuration file has three YAML formatted components
# Order of components does not matter.
#   a) Server Specification
#        Elements:
#          1) Server Port(optional)(default port = 3000)
#          2) Minimum number of workers(optional)(default min_worker = 4)
#          3) Maximum number of workers(optional)(default max_worker = 8)
#          4) Logging level(optional)(default log_level = SEVERE)
#          5) SSL Specification(optional)
#             It defines SSL specification.
#             Parameters:
#               I) SSL Support(optional)(values must be 'enabled' or 'disabled'(default))
#              II) SSL Certificate File(optional)(Path to SSL certificate file. Default is empty)
#             III) SSL Key File(optional)(Path to SSL key file. Default is empty)
#              IV) SSL Port(optional)(Default port number 443)
#          6) Access log(optional)(values must be 'enabled'(default) or 'disabled')
#        Order of the above elements does not matter.
#        Example:
#          Server Specification:
#            port: 3000
#            min_worker: 4
#            max_worker: 8
#            log_level: SEVERE
#            access_log: enabled
#            SSL Specification:
#              ssl_support: enabled
#              certificate_file: /home/smartuser/ca-cert.pem
#              key_file: /home/smartuser/ca-key.pem
#              ssl_port: 443
#
#   b) Application Specification (optional)
#        Elements:
#          1) Application name(mandatory)
#          2) Application baseuri(optional)
#          3) Application path(mandatory)
#          4) Application type(mandatory)(example rails or rack)
#          5) Application environment(optional)(default environment = production)
#          6) Application analytics(mandatory)(values must be 'enabled' or 'disabled')
#          7) Minimum number of workers(optional)(default is 'Server Specification/min_worker')
#          8) Maximum number of workers(optional)(default is 'Server Specification/max_worker')
#          9) Logging level(optional)(default is 'Server Specification/log_level')
#         10) Run as user (mandatory)
#         11) Hostnames(optional)
#         12) Environment Variable(optional)
#             It defines list of environment variables which can be used in the deployed application. It take following parameter.
#             Value is key-value pair separated by equal sign('=') e.g. LOG_DIR=/var/log/webroar
#        Order of the above elements does not matter.
#        Base-uri 'admin-panel' is reserved for 'Admin Panel'.
#        Either host_names or baseuri(not both) must present to resolve HTTP request.
#        Hostnames can have multiple values, each separated by spaces.(e.g. host_names: server.com server.co.in)
#        Hostnames can be defined using wildcard(*), but wildcard can only be at start of name or at end of name (valid hostnames are (i) *.server.com (ii) www.server.* (iii) *.server.*).
#        Prefix Hostname with tilde(~), if wildcard is used in defining Hostname. e.g. (i) ~*.server.com  (ii) ~www.server.*  (iii) ~*.server.*
#        Example with baseuri:
#          Application Specification:
#            - name: Mephisto
#              baseuri: /blog
#              path: /home/smartuser/work/rails_workspace/mephisto
#              type: rails
#              run_as_user: smartuser
#              analytics: enabled
#              environment: production
#              min_worker: 2
#              max_worker: 5
#              log_level: SEVERE
#              environment_variables:
#                - LOG_DIR=/var/log/webroar
#                - TMP_DIR=/tmp
#        Example with host_names:
#          Application Specification:
#            - name: Mephisto
#              host_names: myblog.com ~*.myblog.com
#              path: /home/smartuser/work/rails_workspace/mephisto
#              type: rails
#              run_as_user: smartuser
#              analytics: enabled
#              environment: production
#              min_worker: 2
#              max_worker: 5
#              log_level: SEVERE
#              environment_variables:
#                - set_env: LOG_DIR=/var/log/webroar
#                - set_env: TMP_DIR=/tmp
#
#  (c) Headers (optional)
#        It allows adding or changing the Expires and Cache-Control in the response headers for static assets (e.g. *.js, *.gif etc).
#        Elements:
#          1) Expires header for all static assets (optional) (default is 'off')
#          2) Specific expires header for specific file types (optional)
#             Elements:
#                I) File Extensions(mandatory)
#               II) Expires value(mandatory) (No of seconds)
#        Possible value for expires is off or no. of seconds.
#        Example:
#          Headers:
#            expires: 3600
#            expires_by_type:
#            - ext: png, jpg, gif
#              expires: 31536000
#
#  (d) Encoding (optional)
#        It allows (deflate) encoding of static assets.
#        Elements:
#          1) Regex value for supported Content-Type (optional) (default is 'javascript|css|text|xml')
#          2) Regex value for supported Used-Agent (optional) (default is '.*')
#          3) Range of Content-Length (optional)
#             Elements:
#                I) Lower limit of Content-Length (optional) (default is 10240 i.e. 10KB)
#               II) Upper limit of Content-Length (optional) (default is 1048576 i.e. 1MB)
#        Example:
#          Encoding:
#            Content-Type: text|xml|javascript
#            User-Agent: .*
#            Size Limit:
#              lower_limit: 10240
#              upper_limit: 1048576
#
######################################################################################
}
ADMIN_USER_FILE =
File.join(ADMIN_PANEL_DIR,'config','user.yml')
WEBROAR_CONFIG_FILE =
File.join(WEBROAR_ROOT, 'conf', 'config.yml')
DB_CONFIG_FILE =
File.join(ADMIN_PANEL_DIR, 'config', 'database.yml')
REQUIRED_DEPENDENCIES =
[
  Dependencies::Ruby,
  Dependencies::LibRuby,
  Dependencies::Ruby_OpenSSL,
  Dependencies::RubyZlib,
  Dependencies::Ruby_DevHeaders,
  Dependencies::RubyGems,
  Dependencies::GCC,
  Dependencies::Make,
  Dependencies::Starling,
  Dependencies::Xcode,
  Dependencies::Gnutls,
  Dependencies::Zlib,
  Dependencies::Regex
]

Instance Method Summary collapse

Constructor Details

#initializeInstaller

Returns a new instance of Installer.



191
192
193
194
195
196
197
198
199
# File 'lib/installer.rb', line 191

def initialize
  @options = nil
  @ssl = false
  @import = false
  @port = 0
  @err_msg = nil
  @zlib = true
  @regex = true
end

Instance Method Details

#install(options) ⇒ Object

Install the server



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/installer.rb', line 202

def install(options)

  begin
    return -1 unless User.permitted?
    @options = options

    str = set_install_options

    check_dependencies || exit(1)

    str << " zlib=yes" if @zlib
    str << " regex=yes" if(@zlib and @regex)
    
    @user_interaction = UserInteraction.new(@options)
    @port, @import, gem_name = @user_interaction.user_input
    @port = import_files(gem_name) if @import
    write_server_port if !@import

    create_dirs
    return -1 unless compile_code(str)
    return -1 unless install_server

    # Stop WebROaR if already running.
    WebroarCommand.new.operation(nil, "stop") if File.exist?(PIDFILE)

    # Start WebROaR
    puts"Starting WebROaR ... "
    WebroarCommand.new.operation(nil, "start")

    install_msg(false)
    puts "Warning: " + @err_msg if @err_msg
  rescue Exception=>e
    File.open(File.join(WEBROAR_ROOT, "install.log"), "a+") do |f|
      f.puts e.class.name
      f.puts e.backtrace
    end
  end
end

#test(options) ⇒ Object

Start test cases



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/installer.rb', line 242

def test(options)  # run test-suite comprises of unit test, functional test, admin-panel test, load test
  return -1 unless User.permitted?

  unless (File.exist?(File.join(WEBROAR_BIN_DIR,"webroar-head")) and File.exist?(File.join(WEBROAR_BIN_DIR,"webroar-worker")))
    puts "WebROaR is not installed on this machine."
    install(options)
  end

  @options = options

  # stopping the server.. its get started on installation.
  puts "Please make sure you have made relevant changes in conf/test_suite_config.yml"
  cmd = "webroar stop"
  system(cmd)
  str = ""

  str += "load_test=yes " if @options[:load_test]
  str += "debug_build=yes " if @options[:debug_build]
  str += "no_report=yes " if @options[:no_report]
  str += "report_dir=#{@options[:report_dir] ? @options[:report_dir] : File.join(WEBROAR_ROOT,'report')} "

  Dir.chdir(WEBROAR_ROOT)
  system("rake all_test #{str}")
end

#uninstallObject

Uninstall the server



268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/installer.rb', line 268

def uninstall
  return -1 unless User.permitted?

  if !File.exist?(File.join(WEBROAR_BIN_DIR,"webroar-head")) or !File.exist?(File.join(WEBROAR_BIN_DIR,"webroar-worker"))
    puts "WebROaR is already uninstalled."
    return
  end

  stop_server
  return -1 unless remove_executables
  return -1 unless remove_admin_panel
  remove_log_files
  remove_service_script

end

#versionObject



284
285
286
287
# File 'lib/installer.rb', line 284

def version
  require File.join(WEBROAR_ROOT, 'src', 'ruby_lib', 'ruby_interface','version.rb')
  puts "#{Webroar::SERVER}"
end