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



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

def restart_process
  debug { 'restart_process command' }

  switch :restarting

  if self[:restart_command]
    return unless check_identity
    if execute_restart_command
      sleep_grace(:restart_grace)
    end
    result = process_really_running? || (load_external_pid_file == :ok)
    switch(result ? :restarted : :crashed)
  else
    stop_process
    start_process
  end

  true

rescue StateMachines::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
# 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, reason: '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

    switch :crashed
  end

  result

rescue StateMachines::InvalidTransition, Eye::Process::StateError => 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
64
65
# File 'lib/eye/process/commands.rb', line 39

def stop_process
  debug { 'stop_process command' }

  switch :stopping

  return unless check_identity

  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, reason: 'not stopped (soft command)'
    nil

  else
    switch :stopped

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

    true
  end

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