Class: Eye::Dsl::Opts

Inherits:
PureOpts show all
Defined in:
lib/eye/dsl/opts.rb

Constant Summary collapse

STR_OPTIONS =
[ :pid_file, :working_dir, :stdout, :stderr, :stdall, :start_command,
:stop_command, :restart_command, :uid, :gid ]
BOOL_OPTIONS =
[ :daemonize, :keep_alive, :auto_start, :stop_on_delete, :clear_pid ]
INTERVAL_OPTIONS =
[ :check_alive_period, :start_timeout, :restart_timeout, :stop_timeout, :start_grace,
:restart_grace, :stop_grace, :childs_update_period, :restore_in ]

Instance Attribute Summary

Attributes inherited from PureOpts

#config, #full_name, #name, #parent

Instance Method Summary collapse

Methods inherited from PureOpts

#allow_options, create_options_methods, #disallow_options, #include, #nop, #not_seed_options, #with_condition

Constructor Details

#initialize(name = nil, parent = nil) ⇒ Opts

Returns a new instance of Opts.



19
20
21
22
23
24
25
26
27
# File 'lib/eye/dsl/opts.rb', line 19

def initialize(name = nil, parent = nil)
  super(name, parent)

  @config[:application] = parent.name if parent.is_a?(Eye::Dsl::ApplicationOpts)
  @config[:group] = parent.name if parent.is_a?(Eye::Dsl::GroupOpts)

  # hack for full name
  @full_name = parent.full_name if @name == '__default__'
end

Instance Method Details

#checks(type, opts = {}) ⇒ Object Also known as: check

Raises:



29
30
31
32
33
34
35
36
37
38
# File 'lib/eye/dsl/opts.rb', line 29

def checks(type, opts = {})
  nac = Eye::Checker.name_and_class(type.to_sym)
  raise Eye::Dsl::Error, "unknown checker type #{type}" unless nac

  opts.merge!(:type => nac[:type])
  Eye::Checker.validate!(opts)

  @config[:checks] ||= {}
  @config[:checks][nac[:name]] = opts
end

#nochecks(type) ⇒ Object Also known as: nocheck

clear checks from parent

Raises:



52
53
54
55
56
# File 'lib/eye/dsl/opts.rb', line 52

def nochecks(type)
  nac = Eye::Checker.name_and_class(type.to_sym)
  raise Eye::Dsl::Error, "unknown checker type #{type}" unless nac
  @config[:checks].try :delete, nac[:name]
end

#nonotify(contact) ⇒ Object



79
80
81
82
# File 'lib/eye/dsl/opts.rb', line 79

def nonotify(contact)
  @config[:notify] ||= {}
  @config[:notify].delete(contact.to_s)
end

#notify(contact, level = :warn) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/eye/dsl/opts.rb', line 70

def notify(contact, level = :warn)
  unless Eye::Process::Notify::LEVELS[level]
    raise Eye::Dsl::Error, "level should be in #{Eye::Process::Notify::LEVELS.keys}"
  end

  @config[:notify] ||= {}
  @config[:notify][contact.to_s] = level
end

#notriggers(type) ⇒ Object Also known as: notrigger

clear triggers from parent

Raises:



59
60
61
62
63
# File 'lib/eye/dsl/opts.rb', line 59

def notriggers(type)
  nac = Eye::Trigger.name_and_class(type.to_sym)
  raise Eye::Dsl::Error, "unknown trigger type #{type}" unless nac
  @config[:triggers].try :delete, nac[:name]
end

#scoped(&block) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/eye/dsl/opts.rb', line 110

def scoped(&block)
  h = self.class.new(self.name, self)
  h.instance_eval(&block)
  groups = h.config.delete :groups
  processes = h.config.delete :processes

  if groups.present?
    config[:groups] ||= {}
    config[:groups].merge!(groups)
  end

  if processes.present?
    config[:processes] ||= {}
    config[:processes].merge!(processes)
  end
end

#set_environment(value) ⇒ Object

Raises:



84
85
86
87
88
# File 'lib/eye/dsl/opts.rb', line 84

def set_environment(value)
  raise Eye::Dsl::Error, "environment should be a hash, but not #{value.inspect}" unless value.is_a?(Hash)
  @config[:environment] ||= {}
  @config[:environment].merge!(value)
end

#set_gid(value) ⇒ Object

Raises:



105
106
107
108
# File 'lib/eye/dsl/opts.rb', line 105

def set_gid(value)
  raise Eye::Dsl::Error, ":gid not supported by ruby (needed 2.0)" unless Eye::Settings.supported_setsid?
  super
end

#set_stdall(value) ⇒ Object



93
94
95
96
97
98
# File 'lib/eye/dsl/opts.rb', line 93

def set_stdall(value)
  super

  set_stdout value
  set_stderr value
end

#set_uid(value) ⇒ Object

Raises:



100
101
102
103
# File 'lib/eye/dsl/opts.rb', line 100

def set_uid(value)
  raise Eye::Dsl::Error, ":uid not supported by ruby (needed 2.0)" unless Eye::Settings.supported_setsid?
  super
end

#triggers(type, opts = {}) ⇒ Object Also known as: trigger

Raises:



40
41
42
43
44
45
46
47
48
49
# File 'lib/eye/dsl/opts.rb', line 40

def triggers(type, opts = {})
  nac = Eye::Trigger.name_and_class(type.to_sym)
  raise Eye::Dsl::Error, "unknown trigger type #{type}" unless nac

  opts.merge!(:type => nac[:type])
  Eye::Trigger.validate!(opts)

  @config[:triggers] ||= {}
  @config[:triggers][nac[:name]] = opts
end

#with_server(glob = nil, &block) ⇒ Object

execute part of config on particular server array of strings regexp string



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/eye/dsl/opts.rb', line 131

def with_server(glob = nil, &block)
  on_server = true

  if glob.present?
    host = Eye::System.host

    if glob.is_a?(Array)
      on_server = !!glob.any?{|elem| elem == host}
    elsif glob.is_a?(Regexp)
      on_server = !!host.match(glob)
    elsif glob.is_a?(String) || glob.is_a?(Symbol)
      on_server = (host == glob.to_s)
    end
  end

  scoped do
    with_condition(on_server, &block)
  end

  on_server
end