First of all I must admit that been a Ruby developer for some time now I 
still find *GOD *hard to configure and hard to understand not sure of exact 
reason of this (Lack of documentation or lack of understanding from my part 
)but still fact is even today I'm facing this, perhaps this post might help 
me find those answer as well 

Here are my Problems 

*Problem no 1 ( PID dilemma ) :  *
  Firstly here how my GOD configuration* simple.god* look like 

DIRECTORY = "/Users/joshianiket22/myProject/god_script"God.pid_file_directory = 
DIRECTORYGod.watch do |w|
  w.name = "mess"
  w.start = "ruby /Users/joshianiket22/myProject/god_script/simple.rb"
  w.pid_file =  File.join(DIRECTORY,'simple.pid')
  puts File.join(DIRECTORY,'simple.pid')
  w.stop = "ruby -e 'puts \"#{DateTime.now}\"'"
  w.log = File.join(DIRECTORY,'god.log')
  w.behavior(:clean_pid_file)
  w.interval = 10.seconds
  w.start_if do |start|
    start.condition(:process_running) do |c|
      puts "Inside start condition"
      c.interval = 5.seconds
      c.running = false
    end
  endend

  
Now God Documentation states 

 
<https://lh5.googleusercontent.com/-nhoBajKdV3I/Uh2vK-m8uaI/AAAAAAAAA_g/VH0bMJ855_c/s1600/download+%282%29.png>
 
   
Now if you see my *GOD *configuration file I have specified the *
pid_file_directory*

DIRECTORY = "/Users/joshianiket22/myProject/god_script"God.pid_file_directory = 
DIRECTORY

yet no *PID *(neither of GOD Server nor for the process monitored by GOD is 
stored in that directory) is ever stored in that directory

In fact I have also mention this in my* GOD* configuration 

w.pid_file =  File.join(DIRECTORY,'simple.pid')

but still the same result no *PID *(not even for the *simple.rb* )

BTW, I have started *GOD *
*
*

sudo god -c simple.god

one reason could be that *PID *directory is not writable by GOD ,but to 
tackle that I did *chmod* , *chown* in fact start God using* sudo *
still no luck 


Can anyone explain that now 

FYI , the Log file work btw 

*Problem 2 (Confusion over start_if conditions) *

According to GOD documentation 
<https://lh6.googleusercontent.com/-qFE_V7nOzlg/Uh2ypLb8H5I/AAAAAAAAA_s/y0iNl-onPio/s1600/start_if.png>
Now I get (not exactly) it something like a condition called start only if 
specified condition is met but I don't understand is what is*:process_running
*
is this predefined condition that implies that check for whether a 
processing is running or not If yes what other set of conditions are 
available 

Also what very hard to understand is when would the do block part will be 
executed when *start.condition(:process_running) *return* false or true*because 
I trying to understand the initialization under 
*do* block 

I understand the first part it set the* interval to 5 seconds* to look to 
start as oppose to global interval but what does the c.*running = false *

Now where does this attributes is used and also what are *other list of 
attributes* that we can look for extend the block 

Anyway I think the attributes is used to perform a check something like 
this 

loop(!running)

 ## run start condition until the running is set to true which would happen as 
soon process start running 
 sleep interval ## 5 seconds intervalend


Please feel free to correct me if I'm wrong on this and also please answer 
what are* other list of attributes* *and condition(like :process_running) *that 
we/I can use to extend the block check for *start_if*

FYI, If I remove the start_if my *simple.rb *does not get start at all 
which is weird to me (is this *normal* as well) 


*Problem 3 : Command dilemma (start/stop/restart)*

Given that you looked at  my above configuration script if have a *start 
command written *something like this 
 

w.start = "ruby /Users/joshianiket22/myProject/god_script/simple.rb"

 Now I understand the *start* bit , but is it required to *write/define* the 
stop , restart command as well on our configuration file 

 I assuming Its not ,but you can defined your own *stop, restart* command, 
but if you don't define yours own GOD would take care by defining it own 
stop and restart command (which mean stop the process started by start 
command and other stuff , would be taken care off the hook by GOD are my 
assumptions right.)

Anyways based on my above assumption , when I run  this on my command line 

sudo god stop mess

I get this

Sending 'stop' command
The following watches were affected:
  mess

 but I don't see my *simple.rb *processing getting stopped .

This one of the biggest issue I have seen thus far  ,because  I have seen 
many GOD configuration file which have* start *command written in them but 
not *stop* and *restart* command 

Also , I have another GOD configuration for 
resque<https://github.com/resque/resque>  which 
look like this (*Note* I not using the resque provided GOD configuration 
under example directory) 

APPLICATION_ROOT = '/var/apps/integration/adminapp'RAILS_ENV = 
'integration'God.watch do |w|
  w.env         = {
    'PATH' => 
"/home/deployer/.rbenv/bin:/home/deployer/.rbenv/shims:#{ENV['PATH']}",
    'USER' => 'deployer',
    'HOME' => '/home/deployer',
    'QUEUE'=> '*',
    'TERM_CHILD' => '1',
    'RAILS_ENV' => RAILS_ENV || "production",
    'PIDFILE' => "#{APPLICATION_ROOT}/shared/pids/resque.pid"
  }

  w.uid = 'deployer'
  w.gid = 'deployer'
  w.name = "resque"
  w.interval = 30.seconds
  w.start = "/bin/bash -c 'cd #{APPLICATION_ROOT}/current && . 
/home/deployer/.secrets && /usr/bin/env bundle exec \"RAILS_ENV=#{RAILS_ENV} 
QUEUE=* rake environment resque:work\" '"
  w.log = "#{APPLICATION_ROOT}/shared/log/god_resque.log"
  w.start_grace = 30.seconds
  w.pid_file = "#{APPLICATION_ROOT}/shared/pids/god_minerva.pid"

  w.behavior(:clean_pid_file)

  w.restart_if do |restart| 
    restart.condition(:cpu_usage) do |c| 
      c.above = 50.percent 
      c.times = 5 
    end 
  end 

  # 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
  endend


FYI , again over here the PID is not stored but, that altogether a 
different question that I have address earlier and GOD is started using *
sudo* command

now  you can see that I have *start * command that look like this

 w.start = "/bin/bash -c 'cd #{APPLICATION_ROOT}/current && . 
/home/deployer/.secrets && /usr/bin/env bundle exec \"RAILS_ENV=#{RAILS_ENV} 
QUEUE=* rake environment resque:work\" '"

I don't have *stop* , or *restart* command
*
*
Now in my deploy (VLAD <https://github.com/seattlerb/vlad>) script I have a 
piece of code that look like this (where I send the restart task to God for 
resque) or basically when I do this 

sudo god restart resque

sudo god stop resque

It doesn't do anything and I still see the resque worker running with same*PID 
*
*
*
Can Anyone explain whether or not it is required to define command (like 
stop/restart ) inside GOD configuration file ?
*
*
*Problem 4 (Whether or whether not to put process in background )*


I'll be more specify is this , ideally if I have to put resque worker in 
background (without GOD) I would  run command the following command 

RAILS_ENV=integration QUEUE=* BACKGROUND=yes PID_FILE=resque.pid bundle exec 
rake resque:work

* BACKROUND=yes *is the key over here 

Now I know and according to GOD documentation which states

<https://lh3.googleusercontent.com/-TDlSehfpU-0/Uh3B6-L6-LI/AAAAAAAAA_8/L5QyePNwIis/s1600/download+%283%29.png>


So the question over here whether should I *DAEMONize* my process 
irrespective it run under GOD (which effectively *DAEMONize* at some point) 
or I should *not DAEMONize* it
and let GOD do it .

And Let assume If I *DAEMONize *my process will GOD still keep track of the 
process (like GOD act on restart or stop command for resque which is 
DAEMONize by me) 

to be more precise if I change my *start*  command to  look like this  

w.start = "/bin/bash -c 'cd #{APPLICATION_ROOT}/current && . 
/home/deployer/.secrets && /usr/bin/env bundle exec \"RAILS_ENV=#{RAILS_ENV} 
BACKGROUND=yes QUEUE=* rake environment resque:work\" '"

will GOD still keep track of the above resque process and will it  respond 
to *stop/restart/start* command after doing so

like 

sudo god restart resque

sudo god stop resque

sudo god start resque

Help me out guys in better understanding the GOD monitoring in whole 


Hope I made the everything easy for you guys to understand   


Thanks 

-- 
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.

Reply via email to