Hey,
As a general point of practice in ruby, you shouldn't muck inside of the
gem. (Unless you fork it and re-package it your self).
As for custom conditions, here are some snippets from one I use.
Essentially I want to restart resque scheduler (kind of like a cron) if
someone updates it's schedule (like a crontab file).
So, When I start god, I point it at /etc/god/god.conf. This conf sets up
some stuff and ultimately includes everything in /etc/god/config.d which is
where I keep all my config (in this case god_resque_scheduler_config.rb)
At the top of the resque schedule monitor file I have a monkey patch to
include my custom condition. Eventually, I should consolidate my custom
conditions in their own file and include it before I include the
watches/lifecycles, but that is another day.
module God
module Conditions
class RestartFileTouched < PollCondition
attr_accessor :restart_file
def initialize
super
end
def process_start_time
Time.parse(`ps -o lstart -p #{self.watch.pid} --no-heading`)
end
def restart_file_modification_time
File.mtime(self.restart_file)
end
def valid?
valid = true
valid &= complain("Attribute 'restart_file' must be specified",
self) if self.restart_file.nil?
valid
end
def test
process_start_time < restart_file_modification_time
end
end
end
end
Then in my watch further down the file
God.watch do |w|
<snip non relevant start/stop/basic stuff>
w.restart_if do |restart|
#if schedule updated restart scheduler
restart.condition(:restart_file_touched) do |c|
c.interval = 300.seconds
c.restart_file = File.join(RAILS_ROOT, 'config', 'schedule.yml')
end
end
<snip lifecycle>
end
Adam
On Wednesday, October 9, 2013 6:19:41 AM UTC-4, [email protected] wrote:
>
>
> I'm trying to write a new condition for god, I have 2 questions:
>
> Where should the conditions be placed?
>
> I'm assuming within the conditions folder within the gem structure,
> like: /var/lib/gems/1.9.1/gems/god-0.13.3/lib/god/conditions/
>
> I have named the condition like so: log_seen.rb, the Class within being
> named as LogSeen, however the god log shows:
>
> ERROR: No Condition found with the class name God::Conditions::LogSeen
>
> I assume this is an error with my code in log_seen.rb, how can I
> troubleshoot this further?
>
> It would be good to update the docs with the above information if someone
> knows the answers.
>
> Thanks
> Luke
>
--
You received this message because you are subscribed to the Google Groups
"god.rb" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/god-rb.
For more options, visit https://groups.google.com/groups/opt_out.