Class: ThinService::Command::Commands::Installdaemon

Inherits:
Base
  • Object
show all
Includes:
ServiceInstall
Defined in:
lib/thin_service/command.rb

Instance Attribute Summary

Attributes inherited from Base

#done_validating, #valid

Instance Method Summary collapse

Methods included from ServiceInstall

#add_service, #validate_thin_service_exe

Methods inherited from Base

#failure, #help, #initialize, #options, #valid?, #valid_dir?, #valid_exists?, #valid_file?

Constructor Details

This class inherits a constructor from ThinService::Command::Base

Instance Method Details

#configureObject



245
246
247
248
249
250
251
252
# File 'lib/thin_service/command.rb', line 245

def configure
    options [
      ['-N', '--name SVC_NAME', "Required name for the service to be registered/installed.", :@svc_name, nil],
      ['-D', '--display SVC_DISPLAY', "Adjust the display name of the service.", :@svc_display, nil],
      ['-t', '--task TASK', "Which task to run", :@command, "rake tm:background:start"],
      ['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, Dir.pwd],   
     ]
end

#runObject



281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/thin_service/command.rb', line 281

def run
  bindir_executable = validate_thin_service_exe

  # build the command line
  argv = []

  # start using the native executable
  argv << '"' + bindir_executable + '"'

  # force indication of daemon mode
  argv << "daemon"

  # now the options
  argv << "-c \"#{@cwd}\"" 
  argv << "\"#{@command}\""  


  # concat remaining non-parsed ARGV
  argv.concat(ARGV)

  add_service( @svc_name, @svc_display, argv)
end

#validateObject



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/thin_service/command.rb', line 254

def validate
  @cwd = File.expand_path(@cwd)
  valid_dir? @cwd, "Invalid path to change to: #@cwd"

  # change there to start, then we'll have to come back after daemonize
  Dir.chdir(@cwd)

  valid? @svc_name != nil, "A service name is mandatory."
  valid? !ServiceManager.exist?(@svc_name), "The service already exist, please remove it first."

  # default service display to service name
  @svc_display = @svc_name if !@svc_display

  # start with the premise of app really exist.
  app_exist = true
  %w{app config log}.each do |path|
    if !File.directory?(File.join(@cwd, path))
      app_exist = false
      break
    end
  end

  valid? app_exist == true, "The path you specified isn't a valid Rails application."

  return @valid
end