Class: Loops::Commands::StartCommand

Inherits:
Loops::Command show all
Defined in:
lib/loops/commands/start_command.rb

Instance Attribute Summary

Attributes inherited from Loops::Command

#engine, #options

Instance Method Summary collapse

Methods inherited from Loops::Command

#initialize, #invoke, #requires_bootstrap?

Constructor Details

This class inherits a constructor from Loops::Command

Instance Method Details

#executeObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/loops/commands/start_command.rb', line 2

def execute
  # Pid file check
  if Loops::Daemonize.check_pid(Loops.pid_file)
    puts "Can't start, another process exists!"
    exit(1)
  end

  # Daemonization
  if options[:daemonize]
    app_name = "loops monitor: #{options[:args].join(' ') rescue 'all'}\0"
    Loops::Daemonize.daemonize(app_name)
  end

  # Pid file creation
  Loops::Daemonize.create_pid(Loops.pid_file)

  # Workers processing
  engine.start_loops!(options[:args])

  # Workers exited, cleaning up
  File.delete(Loops.pid_file) rescue nil
end