Class: Navy::Speak

Inherits:
Object
  • Object
show all
Defined in:
lib/navy/speak.rb

Overview

cover your ears…

Direct Known Subclasses

Admiral::Speak, Captain::Speak

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(orders) ⇒ Speak

Returns a new instance of Speak.



6
7
8
# File 'lib/navy/speak.rb', line 6

def initialize(orders)
  @orders = orders
end

Instance Attribute Details

#ordersObject (readonly)

Returns the value of attribute orders.



4
5
6
# File 'lib/navy/speak.rb', line 4

def orders
  @orders
end

Instance Method Details

#after_fork(*args, &block) ⇒ Object

sailor mouth ##



17
18
19
# File 'lib/navy/speak.rb', line 17

def after_fork(*args, &block)
  set_hook(:after_fork, block_given? ? block : args[0])
end

#after_stop(*args, &block) ⇒ Object



21
22
23
# File 'lib/navy/speak.rb', line 21

def after_stop(*args, &block)
  set_hook(:after_stop, block_given? ? block : args[0])
end

#before_fork(*args, &block) ⇒ Object



25
26
27
# File 'lib/navy/speak.rb', line 25

def before_fork(*args, &block)
  set_hook(:before_fork, block_given? ? block : args[0])
end

#before_stop(*args, &block) ⇒ Object



29
30
31
# File 'lib/navy/speak.rb', line 29

def before_stop(*args, &block)
  set_hook(:before_stop, block_given? ? block : args[0])
end

#curse!(file) ⇒ Object



10
11
12
13
# File 'lib/navy/speak.rb', line 10

def curse!(file)
  String === file and return instance_eval(File.read(file), file)
  instance_eval(&file)
end

#heartbeat(*args, &block) ⇒ Object



33
34
35
# File 'lib/navy/speak.rb', line 33

def heartbeat(*args, &block)
  set_hook(:heartbeat, block_given? ? block : args[0], 1)
end

#logger(obj) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/navy/speak.rb', line 37

def logger(obj)
  %w(debug info warn error fatal).each do |m|
    obj.respond_to?(m) and next
    raise ArgumentError, "logger=#{obj} does not respond to method=#{m}"
  end

  orders.set[:logger] = obj
end

#patience(seconds) ⇒ Object



46
47
48
49
50
51
# File 'lib/navy/speak.rb', line 46

def patience(seconds)
  set_int(:patience, seconds, 3)
  # POSIX says 31 days is the smallest allowed maximum timeout for select()
  max = 30 * 60 * 60 * 24
  orders.set[:patience] = seconds > max ? max : seconds
end

#pid(path) ⇒ Object



53
# File 'lib/navy/speak.rb', line 53

def pid(path); set_path(:pid, path); end

#post_fork(*args, &block) ⇒ Object



55
56
57
# File 'lib/navy/speak.rb', line 55

def post_fork(*args, &block)
  set_hook(:post_fork, block_given? ? block : args[0])
end

#preload(*args, &block) ⇒ Object



59
60
61
# File 'lib/navy/speak.rb', line 59

def preload(*args, &block)
  set_hook(:preload, block_given? ? block : args[0], 1)
end

#respawn_limit(respawns, seconds = 1.0) ⇒ Object



63
64
65
66
# File 'lib/navy/speak.rb', line 63

def respawn_limit(respawns, seconds = 1.0)
  set_int(:respawn_limit, respawns, 1)
  orders.set[:respawn_limit_seconds] = seconds
end

#stderr_path(path) ⇒ Object



68
69
70
# File 'lib/navy/speak.rb', line 68

def stderr_path(path)
  set_path(:stderr_path, path)
end

#stdout_path(path) ⇒ Object



72
73
74
# File 'lib/navy/speak.rb', line 72

def stdout_path(path)
  set_path(:stdout_path, path)
end

#timeout(seconds) ⇒ Object



76
77
78
79
80
81
# File 'lib/navy/speak.rb', line 76

def timeout(seconds)
  set_int(:timeout, seconds, 3)
  # POSIX says 31 days is the smallest allowed maximum timeout for select()
  max = 30 * 60 * 60 * 24
  orders.set[:timeout] = seconds > max ? max : seconds
end

#user(user, group = nil) ⇒ Object



83
84
85
86
87
88
# File 'lib/navy/speak.rb', line 83

def user(user, group = nil)
  # raises ArgumentError on invalid user/group
  Etc.getpwnam(user)
  Etc.getgrnam(group) if group
  set[:user] = [ user, group ]
end

#working_directory(path) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/navy/speak.rb', line 90

def working_directory(path)
  # just let chdir raise errors
  path = File.expand_path(path)
  # if config_file &&
  #    config_file[0] != ?/ &&
  #    ! File.readable?("#{path}/#{config_file}")
  #   raise ArgumentError,
  #         "config_file=#{config_file} would not be accessible in" \
  #         " working_directory=#{path}"
  # end
  Dir.chdir(path)
  Navy::Admiral::START_CTX[:cwd] = ENV["PWD"] = path
end