Module: God

Module | God
In: | lib/god.rb lib/god/behavior.rb lib/god/behaviors/clean_pid_file.rb lib/god/behaviors/notify_when_flapping.rb lib/god/cli/command.rb lib/god/cli/run.rb lib/god/cli/version.rb lib/god/condition.rb lib/god/conditions/always.rb lib/god/conditions/complex.rb lib/god/conditions/cpu_usage.rb lib/god/conditions/degrading_lambda.rb lib/god/conditions/disk_usage.rb lib/god/conditions/flapping.rb lib/god/conditions/http_response_code.rb lib/god/conditions/lambda.rb lib/god/conditions/memory_usage.rb lib/god/conditions/process_exits.rb lib/god/conditions/process_running.rb lib/god/conditions/tries.rb lib/god/configurable.rb lib/god/contact.rb lib/god/contacts/email.rb lib/god/dependency_graph.rb lib/god/driver.rb lib/god/errors.rb lib/god/event_handler.rb lib/god/event_handlers/dummy_handler.rb lib/god/event_handlers/kqueue_handler.rb lib/god/event_handlers/netlink_handler.rb lib/god/logger.rb lib/god/metric.rb lib/god/process.rb lib/god/registry.rb lib/god/socket.rb lib/god/system/process.rb lib/god/task.rb lib/god/timeline.rb lib/god/trigger.rb lib/god/watch.rb

### Methods

at_exit contact control internal_init load pattern_match registry running_load running_log setup start status stop_all task terminate uncontact unwatch watch

### Classes and Modules

Module God::Behaviors
Module God::CLI
Module God::Conditions
Module God::Configurable
Module God::Contacts
Module God::System
Class God::AbstractMethodNotOverriddenError
Class God::Behavior
Class God::Condition
Class God::Contact
Class God::DependencyGraph
Class God::Driver
Class God::DriverEvent
Class God::DummyHandler
Class God::EventCondition
Class God::EventHandler
Class God::EventRegistrationFailedError
Class God::InvalidCommandError
Class God::KQueueHandler
Class God::Logger
Class God::Metric
Class God::NetlinkHandler
Class God::NoSuchBehaviorError
Class God::NoSuchConditionError
Class God::NoSuchContactError
Class God::NoSuchWatchError
Class God::PollCondition
Class God::Process
Class God::Registry
Class God::Socket
Class God::Task
Class God::Timeline
Class God::Trigger
Class God::TriggerCondition
Class God::Watch

### Constants

VERSION | = | '0.7.3'
LOG_BUFFER_SIZE_DEFAULT | = | 100
PID_FILE_DIRECTORY_DEFAULTS | = | ['/var/run/god', '~/.god/pids']
DRB_PORT_DEFAULT | = | 17165
DRB_ALLOW_DEFAULT | = | ['127.0.0.1']
LOG_LEVEL_DEFAULT | = | :info

### Attributes

contact_groups | [RW] | internal
contacts | [RW] | internal
groups | [RW] | internal
inited | [RW] | internal
main | [RW] | internal
pending_watch_states | [RW] | internal
pending_watches | [RW] | internal
running | [RW] | internal
server | [RW] | internal
watches | [RW] | internal

### Public Class methods

at_exit()

To be called on program exit to start god

Returns nothing

contact(kind) {|c| ...}

Instantiate a new Contact of the given kind and send it to the block. Then prepare, validate, and record the Contact.

      +kind+ is the contact class specifier

Aborts on invalid kind

              duplicate contact name
              invalid contact
              conflicting group name

Returns nothing

control(name, command)

Control the lifecycle of the given task(s).

      +name+ is the name of a task/group (String)
      +command+ is the command to run (String)
                one of: "start"
                        "monitor"
                        "restart"
                        "stop"
                        "unmonitor"
                        "remove"

Returns String[]:task_names

internal_init()

Initialize internal data.

Returns nothing

load(glob)

Load the given file(s) according to the given glob.

      +glob+ is the glob-enabled path to load

Returns nothing

pattern_match(pattern, list)

Match a shortened pattern against a list of String candidates. The pattern is expanded into a regular expression by inserting .* between each character.

      +pattern+ is the String containing the abbreviation
      +list+ is the Array of Strings to match against

Examples

      list = %w{ foo bar bars }
      pattern = 'br'
      God.pattern_match(list, pattern)
      # => ['bar', 'bars']

Returns String[]:matched_elements

registry()
running_load(code, filename)

Load a config file into a running god instance. Rescues any exceptions that the config may raise and reports these back to the caller.

      +code+ is a String containing the config file
      +filename+ is the filename of the config file

Returns [String[]:task_names, String:errors]

running_log(watch_name, since)

Log lines for the given task since the specified time.

      +watch_name+ is the name of the task (may be abbreviated)
      +since+ is the Time since which to report log lines

Raises God::NoSuchWatchError if no tasks matched

Returns String:joined_log_lines

setup()
start()

Initialize and startup the machinery that makes god work.

Returns nothing

status()

Gather the status of each task.

Examples

      God.status
      # => { 'mongrel' => :up, 'nginx' => :up }

Returns { String:task_name => Symbol:status, … }

stop_all()

Unmonitor and stop all tasks.

Returns true on success

            false if all tasks could not be stopped within 10 seconds

task(klass = Task) {|t| ...}

Instantiate a new, empty Task object and yield it to the mandatory block. The attributes of the task will be set by the configuration file.

Aborts on duplicate task name

              invalid task
              conflicting group name

Returns nothing

terminate()

Force the termination of god.

      * Clean up pid file if one exists
      * Stop DRb service
      * Hard exit using exit!

Never returns because the process will no longer exist!

uncontact(contact)

Remove the given contact from god.

      +contact+ is the Contact to remove

Returns nothing

unwatch(watch)

Unmonitor and remove the given watch from god.

      +watch+ is the Watch to remove

Returns nothing

watch(&block)

Instantiate a new, empty Watch object and pass it to the mandatory block. The attributes of the watch will be set by the configuration file.

Aborts on duplicate watch name

              invalid watch
              conflicting group name

Returns nothing

[Validate]