Class: Installer

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

Constant Summary collapse

CONFIG_HEADER =

include Webroar::UserInteraction

%{
######################################################################################
#                             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)
#        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
#        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
#  (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
#
######################################################################################
}
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::Zlib,
  Dependencies::Ruby_DevHeaders,
  Dependencies::RubyGems,
  Dependencies::GCC,
  Dependencies::Make,
  Dependencies::Starling,
  Dependencies::Xcode,
  Dependencies::Gnutls
]

Instance Method Summary collapse

Constructor Details

#initializeInstaller

Returns a new instance of Installer.



161
162
163
164
165
166
167
# File 'lib/installer.rb', line 161

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

Instance Method Details

#install(options) ⇒ Object

Install the server



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/installer.rb', line 170

def install(options)
  return -1 unless CheckUser.check
  @options = options

  str = set_install_options
    
  
  check_dependencies || exit(1)
    
  @port, @import, gem_name = UserInteraction.new(@options).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
end

#test(options) ⇒ Object

Start test cases



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/installer.rb', line 200

def test(options)  # run test-suite comprises of unit test, functional test, admin-panel test, load test
  return -1 unless CheckUser.check
  @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



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/installer.rb', line 220

def uninstall
  return -1 unless CheckUser.check
    
  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



236
237
238
239
# File 'lib/installer.rb', line 236

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