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
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
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
- Is :process_running a set of condition?, if yes what are other set of condition for start_if
Also what does the attributes inside the do block suppose to do? and when would they be executed?
More precisely I referring to c.running = false ( what it does internal and what other list of attributes are available on start_if)
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
what would happen if run them ?
Will GOD will eventually Kill the running process when stop command i.e
sudo god stop mess' is executed? or restart the running process when restart command i.e
sudo god restart mess` is executed"?
Can anyone share light on it
Confusion 4 (Whether or whether not to daemonize the process):
According to GOD documentation
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
- Will GOD monitor them for stop and restart command ?
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
Why isn't the pid_file_directory syntax working?
if :process_running is a set of conditions what other conditions does start_if contains also what c.running = false (internally do)
Is it necessary to write/define
stop
andrestart
in God configurationIf the process is explicity move to background will GOD still monitor it for command like
stop|restart
etc
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
forstop
andrestart
Straight from GOD documentation
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 backgroundAgain from GOD documentation
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
What other conditions does
start_if
contains ?Ans:
Well the best place to look that is under conditions directory of god check over here there isprocess_running
condition also existsWhat c.running = false (internally do)?
Ans:
Well c.running is internally used to check (the check is perform with respect to process id and running variable) whether a process was running prior whengod
start so if the process i.e(c.running = true) is running and thepid
file pointed has the corrected all work well but if thec.running = true
andpid
monitored is different or does not exist it keep looping hence it advisable to usec.running = true
only if the process was already running and correctpid_file
(with correctpid
in it is) is define in god file . One can check that over hereNote: 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.