Class: Rays::Controller

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/rays/interface/controller.rb

Instance Method Summary collapse

Instance Method Details

#backupObject



205
206
207
208
209
210
# File 'lib/rays/interface/controller.rb', line 205

def backup
  log_block("backup") do
    package = Rays::Service::Backup.new.backup
    $log.info("Backup created: <!#{package}!>")
  end
end

#build(skip_test, modules = nil) ⇒ Object

Build module(s)



75
76
77
78
79
80
81
82
83
84
# File 'lib/rays/interface/controller.rb', line 75

def build(skip_test, modules = nil)
  show_environment_info
  log_block("build module(s)") do
    unless modules.nil?
      modules.each do |app_module|
        app_module.build skip_test
      end
    end
  end
end

#clean(modules = nil) ⇒ Object

Clean module(s).



118
119
120
121
122
123
124
125
126
127
# File 'lib/rays/interface/controller.rb', line 118

def clean(modules=nil)
  show_environment_info
  log_block("deploy module(s)") do
    unless modules.nil?
      modules.each do |app_module|
        app_module.clean
      end
    end
  end
end

#clean_solr_indexObject

Clean solr index



337
338
339
340
341
342
# File 'lib/rays/interface/controller.rb', line 337

def clean_solr_index
  show_environment_info
  log_block("clean solr index") do
    $rays_config.environment.solr.clean_all
  end
end

#create_module(type, name, generator) ⇒ Object

Create a module



65
66
67
68
69
70
# File 'lib/rays/interface/controller.rb', line 65

def create_module(type, name, generator)
  name = "#{name}-#{type}" unless type.eql? 'ext'
  log_block("create #{type} #{name}") do
    AppModule::Manager.instance.create type, name, generator
  end
end

#create_project(project_name) ⇒ Object

Create new project



33
34
35
36
37
38
# File 'lib/rays/interface/controller.rb', line 33

def create_project(project_name)
  log_block("create project #{project_name}") do
    Project.create project_name
    $log.warn("setup your project environments in #{$rays_config.project_root}/config/environment.yml")
  end
end

#current_environmentObject

Environment methods



132
133
134
135
136
# File 'lib/rays/interface/controller.rb', line 132

def current_environment
  log_block("get environment name") do
    $log.info("<!#{$rays_config.environment.name}!>")
  end
end

#deploy(skip_test, modules = nil) ⇒ Object

Build and deploy module(s).



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/rays/interface/controller.rb', line 89

def deploy(skip_test, modules = nil)
  show_environment_info
  log_block("build and deploy module(s)") do
    unless modules.nil?
      modules.each do |app_module|
        app_module.build skip_test
        app_module.deploy
      end
    end
  end
end

#deploy_no_build(modules = nil) ⇒ Object

Deploy module(s). No build.



104
105
106
107
108
109
110
111
112
113
# File 'lib/rays/interface/controller.rb', line 104

def deploy_no_build(modules=nil)
  show_environment_info
  log_block("deploy module(s)") do
    unless modules.nil?
      modules.each do |app_module|
        app_module.deploy
      end
    end
  end
end

#go(name) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/rays/interface/controller.rb', line 182

def go(name)
  log_block("switch directory") do
    points = $rays_config.points
    point_name = name
    point_name ||= 'default'
    dir = ''
    if "appserver".eql? name
      dir = $rays_config.environments['local'].liferay.service.path
    elsif !points.nil? and points.include?(point_name)
      dir = points[point_name]
    else
      raise RaysException.new("no point #{name}. use <!rays point!> to create points")
    end

    if Dir.exists?(dir)
      $log.info("<!#{dir}!>") # tricky part. it logs to shell the directory name which will be switch by a bash script.
    else
      raise RaysException
    end

  end
end

#init_projectObject

init project on the current directory



43
44
45
46
47
48
# File 'lib/rays/interface/controller.rb', line 43

def init_project
  log_block("init project") do
    Project.init
    $log.warn("setup your project environments in #{$rays_config.project_root}/config/environment.yml")
  end
end

#liferay_debug(force = false) ⇒ Object

Start liferay’s application server in debug mode



276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/rays/interface/controller.rb', line 276

def liferay_debug(force=false)
  show_environment_info
  task('starting server in debug mode', 'start debug command has been sent', 'failed to start the server in debug mode') do
    service = $rays_config.environment.liferay.service
    if service.remote? and !force
      $log.warn("WARNING: you are trying to debug a remote server.")
      $log.warn("Your current environment is <!#{$rays_config.environment.name}!>.")
      $log.warn("Use <!--force!> option if you really want to start remote liferay server.")
      return
    end
    service.debug
  end
end

#liferay_logObject

Show liferay server logs



326
327
328
329
330
331
332
# File 'lib/rays/interface/controller.rb', line 326

def liferay_log
  show_environment_info
  task('show server log', '', 'cannot access server log file') do
    service = $rays_config.environment.liferay.service
    service.log
  end
end

#liferay_restart(force = false) ⇒ Object

Restart liferay’s application server



242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/rays/interface/controller.rb', line 242

def liferay_restart(force=false)
  show_environment_info
  task('restarting server', 'stop and start command has been sent', 'failed to start the server') do
    service = $rays_config.environment.liferay.service
    if service.remote? and !force
      $log.warn("WARNING: you are trying to start a remote server.")
      $log.warn("Your current environment is <!#{$rays_config.environment.name}!>.")
      $log.warn("Use <!--force!> option if you really want to start remote liferay server.")
      return
    end
    service.restart_normal
  end
end

#liferay_restart_debug(force = false) ⇒ Object

Restart liferay’s application server in debug mode



259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/rays/interface/controller.rb', line 259

def liferay_restart_debug(force=false)
  show_environment_info
  task('restarting server in debug mode', 'stop and debug command has been sent', 'failed to start the server') do
    service = $rays_config.environment.liferay.service
    if service.remote? and !force
      $log.warn("WARNING: you are trying to start a remote server.")
      $log.warn("Your current environment is <!#{$rays_config.environment.name}!>.")
      $log.warn("Use <!--force!> option if you really want to start remote liferay server.")
      return
    end
    service.restart_debug
  end
end

#liferay_start(force = false) ⇒ Object

Start liferay’s application server



225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/rays/interface/controller.rb', line 225

def liferay_start(force=false)
  show_environment_info
  task('starting server', 'start command has been sent', 'failed to start the server') do
    service = $rays_config.environment.liferay.service
    if service.remote? and !force
      $log.warn("WARNING: you are trying to start a remote server.")
      $log.warn("Your current environment is <!#{$rays_config.environment.name}!>.")
      $log.warn("Use <!--force!> option if you really want to start remote liferay server.")
      return
    end
    service.start
  end
end

#liferay_statusObject

Show liferay server status



310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/rays/interface/controller.rb', line 310

def liferay_status
  show_environment_info
  log_block('get server status') do
    service = $rays_config.environment.liferay.service

    if service.alive?
      $log.info("running on #{service.host}:#{service.port}")
    else
      $log.info("stopped")
    end
  end
end

#liferay_stop(force = false) ⇒ Object

Stop liferay’s application server



293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/rays/interface/controller.rb', line 293

def liferay_stop(force=false)
  show_environment_info
  task('stopping server', 'stop command has been sent', 'failed to stop the server') do
    service = $rays_config.environment.liferay.service
    if service.remote? and !force
      $log.warn("WARNING: you are trying to stop a remote server.")
      $log.warn("Your current environment is <!#{$rays_config.environment.name}!>.")
      $log.warn("Use <!--force!> option if you really want to stop remote liferay server.")
      return
    end
    service.stop
  end
end

#list_environmentsObject



138
139
140
141
142
# File 'lib/rays/interface/controller.rb', line 138

def list_environments
  log_block("get environments list") do
    $log.info("<!#{$rays_config.environments.keys.join(" ")}!>")
  end
end

#point(path, name) ⇒ Object

Point methods



154
155
156
157
158
159
160
161
162
# File 'lib/rays/interface/controller.rb', line 154

def point(path, name)
  if 'appserver'.eql?(name)
    $log.error('reserved point name')
    return
  end
  log_block("remember a point") do
    $rays_config.point(path, name)
  end
end

#pointsObject



164
165
166
167
168
169
170
171
172
173
174
# File 'lib/rays/interface/controller.rb', line 164

def points
  log_block("show points") do
    unless $rays_config.points.nil?
      $rays_config.points.each_key do |point|
        $log.info("#{point}: <!#{$rays_config.points[point]}!>")
      end
    else
      $log.info('No points found')
    end
  end
end

#remove_point(name) ⇒ Object



176
177
178
179
180
# File 'lib/rays/interface/controller.rb', line 176

def remove_point(name)
  log_block("remove a point") do
    $rays_config.remove_point(name)
  end
end

#show_modulesObject

Show modules



53
54
55
56
57
58
59
# File 'lib/rays/interface/controller.rb', line 53

def show_modules
  log_block("show modules") do
    AppModule::Manager.instance.all.each do |appmodule|
      $log.info("#{appmodule.type}: <!#{appmodule.name}!>")
    end
  end
end

#solr_logObject

Show solr server logs



396
397
398
399
400
401
402
# File 'lib/rays/interface/controller.rb', line 396

def solr_log
  show_environment_info
  task('show server log', '', 'cannot access server log file') do
    service = $rays_config.environment.solr.service
    service.log
  end
end

#solr_start(force = false) ⇒ Object

Start solr application server



347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/rays/interface/controller.rb', line 347

def solr_start(force=false)
  show_environment_info
  task('starting server', 'start command has been sent', 'failed to start the server') do
    service = $rays_config.environment.solr.service
    if service.remote? and !force
      $log.warn("WARNING: you are trying to start a remote server.")
      $log.warn("Your current environment is <!#{$rays_config.environment.name}!>.")
      $log.warn("Use <!--force!> option if you really want to start a remote solr server.")
      return
    end
    service.start
  end
end

#solr_statusObject

Show solr server status



381
382
383
384
385
386
387
388
389
390
391
# File 'lib/rays/interface/controller.rb', line 381

def solr_status
  show_environment_info
  log_block('get server status') do
    service = $rays_config.environment.solr.service
    if service.alive?
      $log.info("running on #{service.host}:#{service.port}")
    else
      $log.info("stopped")
    end
  end
end

#solr_stop(force = false) ⇒ Object

Stop solr application server



364
365
366
367
368
369
370
371
372
373
374
375
376
# File 'lib/rays/interface/controller.rb', line 364

def solr_stop(force=false)
  show_environment_info
  task('stopping server', 'stop command has been sent', 'failed to stop the server') do
    service = $rays_config.environment.solr.service
    if service.remote? and !force
      $log.warn("WARNING: you are trying to stop a remote server.")
      $log.warn("Your current environment is <!#{$rays_config.environment.name}!>.")
      $log.warn("Use <!--force!> option if you really want to stop a remote solr server.")
      return
    end
    service.stop
  end
end

#switch_environment(env_name) ⇒ Object



144
145
146
147
148
149
# File 'lib/rays/interface/controller.rb', line 144

def switch_environment(env_name)
  log_block("switch environment") do
    $rays_config.environment = env_name
    $log.info("<!#{env_name}!>")
  end
end

#syncObject



212
213
214
215
216
217
218
219
220
# File 'lib/rays/interface/controller.rb', line 212

def sync
  if 'local'.eql?($rays_config.environment.name)
    $log.warn("Select not local environment to import to local.")
    return
  end
  log_block("synchronize environments") do
    Rays::Service::Sync.new.sync
  end
end