Class: EaseEngine::Process

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

Class Method Summary collapse

Class Method Details

.daemon(path, is_daemon, *args, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ease_engine/process.rb', line 10

def self.daemon( path, is_daemon, *args, &block )
  pid_file_path = "#{path}.pid"
  begin
    if File.exist?( pid_file_path )
      EaseEngine::Log.err "PID file exist: #{pid_file_path}"
      break
    end
    
    ::Process.daemon( *args ) if is_daemon
    File.open( pid_file_path, "wb" ){|file|
      file.puts "#{::Process.pid}"
    }
    log_file = File.open( "#{path}.log", "a+b" )
    if ! log_file.nil?
      block.call( log_file, pid_file_path )
      log_file.close
    end
    File.delete pid_file_path if File.exist?( pid_file_path )
  end while false
end

.execute(cmd, option = {}) ⇒ Object



5
6
7
8
# File 'lib/ease_engine/process.rb', line 5

def self.execute( cmd, option = {} )
  out, err, status = Open3.capture3( cmd, option )
  [ status.exitstatus, out, err ]
end