rubygodprocess-monitoring

Trying to understand GOD rb


I'm facing few confusion with GOD documentation

Firstly my configuration script look like this

DIRECTORY = "/Users/joshianiket22/myProject/god_script"
God.pid_file_directory = DIRECTORY
God.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 
  end 
end

Confusion 1 : GOD PID FILE DILEMMA

In GOD documentation it mention

enter image description here

Now I have clear I have set the pid_file and pid_file_directory yet the PID is no where to be seen in that directory that is define in my configuration

FYI, started GOD with sudo so assuming directory would be writable by GOD

Confusion 2: START_IF CONDITION

enter image description here

Now That how one define a start_if condition now I not able to understand the use case for this. Also word condition what conditions to set of conditions

Confusion 3 (start/stop/restart command)

Now given my configuration file which has a start command written in it, now is it also required to write a stop and restart command as well in configuration

so that when run the following

sudo god stop mess
sudo god restart mess

they would get executed

Assuming I don't write them

Can anyone share light on it

Confusion 4 (Whether or whether not to daemonize the process):

According to GOD documentation enter image description here

Now Consider I explicitly put by process to background inside GOD something like

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

what would happen in such case

So daemonizing your process inside GOD (in start command ) can be consider a valid approach assuming that GOD know that the process has gone in background and it react to all command start / stop / restart command on that process when run against GOD ?

like

sudo god stop mess
sudo god restart mess

Can anyone put some light on this as well

So here are list of question extracted from above


Solution

  • Partially answer some part of my question

    Question: Is it necessary to write/define stop and restart in God configuration

    Answer Well not really you can define your own command but if in case you dont define there is default lambda for stop and restart

    Straight from GOD documentation

    enter image description here

    Question: If the process is explicity move to background will GOD still monitor it for command like stop|restart etc

    Answer: Answer is YES and NO , No because if you dont give GOD the pid file to monitor it will not monitor the process running in background

    Again from GOD documentation

    enter image description here

    Question: If :process_running is a set of conditions what other conditions does start_if contains also what c.running = false (internally do)

    Answer: Well I will answer this question in 2 parts

    Note: Accepting my answer since only one question is left and I believe it was mostly not working because of my wrong doing (i.e the pid wasn't getting stored in desired directory) :) Rest all question are answered by me.