Module: Eye::Process::Commands

Included in:
ChildProcess, Eye::Process
Defined in:
lib/eye/process/commands.rb

Instance Method Summary collapse

Instance Method Details

#restart_processObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/eye/process/commands.rb', line 66

def restart_process
  debug { 'restart_process command' }

  switch :restarting

  if self[:restart_command]
    execute_restart_command
    sleep_grace(:restart_grace)
    result = check_alive_with_refresh_pid_if_needed
    switch(result ? :restarted : :crashed)
  else
    stop_process
    start_process
  end

  true

rescue StateMachine::InvalidTransition, Eye::Process::StateError => e
  warn "wrong switch '#{e.message}'"
  nil
end

#start_processObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/eye/process/commands.rb', line 3

def start_process
  debug { 'start_process command' }

  switch :starting

  unless self[:start_command]
    warn 'no :start_command found, unmonitoring'
    switch :unmonitoring, Eye::Reason.new(:no_start_command)
    return :no_start_command
  end

  result = self[:daemonize] ? daemonize_process : execute_process

  if !result[:error]
    debug { "process <#{self.pid}> started successfully" }
    switch :started
  else
    error "process <#{self.pid}> failed to start (#{result[:error].inspect})"

    if process_really_running?
      warn "killing <#{self.pid}> due to error"
      send_signal(:KILL)
      sleep 0.2 # little grace
    end

    self.pid = nil
    switch :crashed
  end

  result

rescue StateMachine::InvalidTransition, Eye::Process::StateError => e
  warn "wrong switch '#{e.message}'"

  :state_error
end

#stop_processObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/eye/process/commands.rb', line 40

def stop_process
  debug { 'stop_process command' }

  switch :stopping

  kill_process

  if process_really_running?
    warn "process <#{self.pid}> was not stopped; try checking your command/signals or tuning the stop_timeout/stop_grace values"

    switch :unmonitoring, Eye::Reason.new(:'not stopped (soft command)')
    nil

  else
    switch :stopped

    clear_pid_file if self[:clear_pid] # by default for all

    true
  end

rescue StateMachine::InvalidTransition, Eye::Process::StateError => e
  warn "wrong switch '#{e.message}'"
  nil
end