Trying to get a simple God demo working.
In an empty directory I created the following files as per the God documentation:
simple.rb:
loop do
puts 'Hello'
sleep 1
end
simple.rb:
God.watch do |w|
w.name = "simple"
w.start = "ruby simple.rb"
w.log = 'myprocess.log'
w.keepalive
end
Then I run:
$ sudo god -c simple.god -D
and get this output:
I [2018-10-31 23:19:39] INFO: Loading simple.god
I [2018-10-31 23:19:39] INFO: Syslog enabled.
I [2018-10-31 23:19:39] INFO: Using pid file directory: /var/run/god
I [2018-10-31 23:19:39] INFO: Started on drbunix:///tmp/god.17165.sock
I [2018-10-31 23:19:39] INFO: simple move 'unmonitored' to 'init'
I [2018-10-31 23:19:39] INFO: simple moved 'unmonitored' to 'init'
I [2018-10-31 23:19:39] INFO: simple [trigger] process is running (ProcessRunning)
I [2018-10-31 23:19:39] INFO: simple move 'init' to 'up'
I [2018-10-31 23:19:39] INFO: simple registered 'proc_exit' event for pid 11741
I [2018-10-31 23:19:39] INFO: simple moved 'init' to 'up'
but I can't seem to capture the actual output from the watched process. The 'myprocess.log' file never gets created or written to.
But beyond that I'm just experiencing some really weird behavior. Like sometimes when I run it it spews an endless stream of output showing processes starting and exiting one after another. Sometimes it logs to files after I've renamed them. I can't get a peg on why it's behaving so erratically.
God 0.13.7 / ruby 2.3.0 / OSX 10.13.6
Check the example in the documentation that you linked to again:
You are using a relative path, not a full path. If you try to use a relative path it's going to error out and say it can't create the log file there. This will cause it to loop through start/exit as you described.
Also, make sure that after you
CTRL-Cthegodprocess that you kill your backgroundedrubyprocess. You can see that even after killinggodthat it's running withps aux | grep ruby.Finally,
putsdoes log to the log file, but the output is buffered bygoduntil therubyprocess forsimple.rbis terminated. Repeat this process to confirm:Switch to a new shell and run:
I recommend you keep reading the documentation for
god. There's a lot to it, and the answers are all there.