God: A Ruby framework for process
management.
The core issue we face before using the
explanation of the use of process managment tools/gems:
While I have implemented sidekiq to
monitor the threads in our application for sending emails in certain
time frames. The sidekiq stops if server reboots and the queued
processes goes in a indefinite period of time without execution. So
this needs the sidekiq should be restarted automatically when it
stops.
God is a framework which can automate
the process.
FEATURES
- Config file is written in Ruby
- Easily write your own custom conditions in Ruby
- Supports both poll and event based conditions
- Different poll conditions can have different intervals
- Integrated notification system (write your own too!)
- Easily control non-daemonizing scripts
Installation
Add gem 'god' in Gemfile .
Run $ bundle install
Or
Run $ [sudo] install gem god
Github source :
https://github.com/mojombo/god
Version
$ god –version
God Learning Curve
Let us start with basic examples, how
to write codes to execute the processes using God.
Let us create a new file god_demo.rb in
application folder.
Write the following code in the same
file
loop do
puts 'Hello'
sleep 1
end
Now we'll write a god config file that
tells god about our process. Place it in the same directory and call
it god_demo .god:
God.watch do |w|
w.name = "god_demo"
w.start = "ruby
/full/path/to/god_demo.rb"
w.keepalive
end
God configuration should start with a
God.watch block. A watch in god represents a process that we want to
watch and control. Each watch must have, at minimum, a unique name
and a command that tells god how to start the process.
The keepalive declaration denotes
god to keep this process alive. If the process is not running when
god starts, it will be started. If the process dies, it will be
restarted.
To run god, we give it the
configuration file we wrote with -c. To
see what's going on, we can ask it to run foreground with -D:
There are two ways that god can monitor
your process. The first and better way is with process events. Not
every system supports it, but those that do will automatically use
it. With events, god will know immediately when a process exits. For
those systems without process event support, god will use a polling
mechanism. The output you see throughout this section will show both
ways.
This is the example in
http://godrb.com/
# Events
I [2011-12-10 15:24:34] INFO: Loading
simple.god
I [2011-12-10 15:24:34] INFO: Syslog
enabled.
I [2011-12-10 15:24:34] INFO: Using
pid file directory: /Users/tom/.god/pids
I [2011-12-10 15:24:34] INFO: Started
on drbunix:///tmp/god.17165.sock
I [2011-12-10 15:24:34] INFO: simple
move 'unmonitored' to 'init'
I [2011-12-10 15:24:34] INFO: simple
moved 'unmonitored' to 'init'
I [2011-12-10 15:24:34] INFO: simple
[trigger] process is not running (ProcessRunning)
I [2011-12-10 15:24:34] INFO: simple
move 'init' to 'start'
I [2011-12-10 15:24:34] INFO: simple
start: ruby /Users/tom/dev/mojombo/god/simple.rb
I [2011-12-10 15:24:34] INFO: simple
moved 'init' to 'start'
I [2011-12-10 15:24:34] INFO: simple
[trigger] process is running (ProcessRunning)
I [2011-12-10 15:24:34] INFO: simple
move 'start' to 'up'
I [2011-12-10 15:24:34] INFO: simple
registered 'proc_exit' event for pid 23298
I [2011-12-10 15:24:34] INFO: simple
moved 'start' to 'up'
# Polls
I [2011-12-07 09:40:18] INFO: Loading
simple.god
I [2011-12-07 09:40:18] INFO: Syslog
enabled.
I [2011-12-07 09:40:18] INFO: Using
pid file directory: /Users/tom/.god/pids
I [2011-12-07 09:40:18] INFO: Started
on drbunix:///tmp/god.17165.sock
I [2011-12-07 09:40:18] INFO: simple
move 'unmonitored' to 'up'
I [2011-12-07 09:40:18] INFO: simple
moved 'unmonitored' to 'up'
I [2011-12-07 09:40:18] INFO: simple
[trigger] process is not running (ProcessRunning)
I [2011-12-07 09:40:18] INFO: simple
move 'up' to 'start'
I [2011-12-07 09:40:18] INFO: simple
start: ruby /Users/tom/dev/mojombo/god/simple.rb
I [2011-12-07 09:40:19] INFO: simple
moved 'up' to 'up'
I [2011-12-07 09:40:19] INFO: simple
[ok] process is running (ProcessRunning)
I [2011-12-07 09:40:24] INFO: simple
[ok] process is running (ProcessRunning)
I [2011-12-07 09:40:29] INFO: simple
[ok] process is running (ProcessRunning)
No comments:
Post a Comment