-
-
Save pangkalizer/91efb6388fa8ee57d64e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# god Startup script for god (http://god.rubyforge.org) | |
# | |
# chkconfig: - 85 15 | |
# description: God is an easy to configure, easy to extend monitoring \ | |
# framework written in Ruby. | |
# | |
CONF_DIR=/etc/god | |
GOD_BIN=$GEM_HOME/bin/god | |
RUBY_BIN=~/.rvm/bin/ruby | |
RETVAL=0 | |
# Go no further if config directory is missing. | |
[ -d "$CONF_DIR" ] || exit 0 | |
case "$1" in | |
start) | |
# Create pid directory | |
$RUBY_BIN $GOD_BIN -c $CONF_DIR/master.conf | |
RETVAL=$? | |
;; | |
stop) | |
$RUBY_BIN $GOD_BIN terminate | |
RETVAL=$? | |
;; | |
restart) | |
$RUBY_BIN $GOD_BIN terminate | |
$RUBY_BIN $GOD_BIN -c $CONF_DIR/master.conf | |
RETVAL=$? | |
;; | |
status) | |
$RUBY_BIN $GOD_BIN status | |
RETVAL=$? | |
;; | |
*) | |
echo "Usage: god {start|stop|restart|status}" | |
exit 1 | |
;; | |
esac | |
exit $RETVAL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load "[APPLICATION_ROOT]/current/gods/resque-pool-production.god" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rails_env = ENV['RAILS_ENV'] || 'production' | |
rails_root = File.expand_path(File.join(File.dirname(__FILE__),'..')) | |
God.watch do |w| | |
w.dir = "#{rails_root}" | |
w.name = "resque-pool" | |
w.group = 'resque' | |
w.interval = 30.seconds | |
w.env = { "RAILS_ENV" => rails_env } | |
w.start = "bundle exec resque-pool -d -o #{rails_root}/log/resque-pool.stdout -e #{rails_root}/log/resque-pool.stderr -p #{rails_root}/tmp/pids/resque-pool.pid" | |
w.pid_file = "#{rails_root}/tmp/pids/resque-pool.pid" | |
w.behavior(:clean_pid_file) | |
# determine the state on startup | |
w.transition(:init, { true => :up, false => :start }) do |on| | |
on.condition(:process_running) do |c| | |
c.running = true | |
end | |
end | |
# determine when process has finished starting | |
w.transition([:start, :restart], :up) do |on| | |
on.condition(:process_running) do |c| | |
c.running = true | |
c.interval = 5.seconds | |
end | |
# failsafe | |
on.condition(:tries) do |c| | |
c.times = 5 | |
c.transition = :start | |
c.interval = 5.seconds | |
end | |
end | |
# start if process is not running | |
w.transition(:up, :start) do |on| | |
on.condition(:process_running) do |c| | |
c.running = false | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment