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



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

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 => 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
# 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, so 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}) ok started"
    switch :started
  else
    error "process (#{self.pid}) failed to start (#{result[:error].inspect})"
    if process_realy_running?
      warn "kill, what remains from process (#{self.pid}), because its failed to start (without pid_file impossible to monitoring)"
      send_signal(:KILL)
      sleep 0.2 # little grace
    end

    self.pid = nil
    switch :crashed
  end

  result

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

  :state_error
end

#stop_processObject



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

def stop_process
  debug 'stop_process command'

  switch :stopping

  kill_process

  if process_realy_running?
    warn 'NOT STOPPED, check command/signals, or tune stop_timeout/stop_grace, seems it was really soft'

    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 => e
  warn "wrong switch '#{e.message}'"
  nil
end