god
god copied to clipboard
God can not support setting environment variables in the start command to launch other service
I am trying to use god to manage a ruby process named clockworkd. It need the RAILS_ENV to load the special environment mode like:
RAILS_ENV=development bundle exec clockworkd ...
- I tried this command standalone and it succeed.
- Use god to start it, failed:
clockwork start: RAILS_ENV=development bundle exec clockworkd ... tao800_fire-sidekiq-0 moved 'unmonitored' to 'init' tao800_fire-sidekiq-1 move 'unmonitored' to 'init' tao800_fire-sidekiq-1 moved 'unmonitored' to 'init' tao800_fire-sidekiq-2 move 'unmonitored' to 'init' tao800_fire-sidekiq-2 moved 'unmonitored' to 'init' clockwork start command exited with non-zero code = 1
3 delete RAILS_ENV=development in the god cmd, succeed:
clockwork start: bundle exec clockworkd -c log start
clockwork moved 'init' to 'start'
clockwork [ok] process is not running (Proc
clockwork [ok] tries within bounds [1/5] (T
clockwork [trigger] process is running (Pro
clockwork move 'start' to 'up'
clockwork moved 'start' to 'up'
I wonder if it is a God issue. But is there any way to solve this problem?
bundle exec must be done in the project directory that has the Gemfile
Which depending on where your god is installed May or May not be true.
cd x/y/z && bundle exec ...
On Jul 2, 2014, at 1:43 AM, "tomwang" <[email protected]mailto:[email protected]> wrote:
I am trying to use god to manage a ruby process named clockworkd. It need the RAILS_ENV to load the special environment mode like:
RAILS_ENV=development bundle exec clockworkd ...
- I tried this command standalone and it succeed.
- Use god to start it, failed:
clockwork start: RAILS_ENV=development bundle exec clockworkd ... tao800_fire-sidekiq-0 moved 'unmonitored' to 'init' tao800_fire-sidekiq-1 move 'unmonitored' to 'init' tao800_fire-sidekiq-1 moved 'unmonitored' to 'init' tao800_fire-sidekiq-2 move 'unmonitored' to 'init' tao800_fire-sidekiq-2 moved 'unmonitored' to 'init' clockwork start command exited with non-zero code = 1
- delete RAILS_ENV=development in the god cmd, succeed:
clockwork start: bundle exec clockworkd -c log start clockwork moved 'init' to 'start' clockwork [ok] process is not running (Proc clockwork [ok] tries within bounds [1/5] (T clockwork [trigger] process is running (Pro clockwork move 'start' to 'up' clockwork moved 'start' to 'up'
I wonder if it is a God issue. But is there any way to solve this problem?
— Reply to this email directly or view it on GitHubhttps://github.com/mojombo/god/issues/180.
@donovanbray i add cd RAILS_ROOT && " and failed the same error. It seemed to be a matter of environment variable not working, not of bundle exec.
can you gist your entire config file?
https://gist.github.com/tomwang1013/5b9c427009ba6cca16a8
You should definitely be using w.env = { } instead of putting environment variables on the command line.
Also, the w.dir = directive is the right way instead of the cd RAILS_ROOT && stuff.
@eric i update the god as you said:
base_cmd = "bundle exec clockworkd ..."
w.env = { RAILS_ENV: RAILS_ENV }
w.dir = RAILS_ROOT
w.name = 'clockwork'
Still failed the same error:
WARN: clockwork start command exited with non-zero code = 1. And the command succeed when running standalone:
bundle exec clockworkd -c /home/wangxiantong/projects/tao800_fire/clock.rb -l --pid-dir=/home/wangxiantong/projects/tao800_fire/tmp --log-dir=/home/wangxiantong/projects/tao800_fire/log start
I think the devil is in your paths. Output the value of base_cmd to stdout or put in a debugger and stop it at line 15 and double check you are getting the string you expect for the base_cmd
also when you run the bundle exec clockworkd manually check the exit code.
bundle exec clockworkd -c /home/wangxiantong/projects/tao800_fire/clock.rb -l --pid-dir=/home/wangxiantong/projects/tao800_fire/tmp --log-dir=/home/wangxiantong/projects/tao800_fire/log start
echo $?
@donovanbray tried, $? is 0. The command has no problem
gist the complete log output during a start for lines that begin with "clockwork"
because in the only logs you've pasted the command god is executing is
clockwork start: bundle exec clockworkd -c log start
which doesn't match your manual execution.
god -c god/clockwork.god -D output:
Notice the WARN: clockwork start command exited with non-zero code = 1
I [2014-07-04 09:17:11] INFO: Loading god/clockwork.god
I [2014-07-04 09:17:11] INFO: Syslog enabled.
I [2014-07-04 09:17:11] INFO: Using pid file directory: /home/wangxiantong/.god/pids
I [2014-07-04 09:17:11] INFO: Started on drbunix:///tmp/god.17165.sock
I [2014-07-04 09:17:11] INFO: clockwork move 'unmonitored' to 'init'
I [2014-07-04 09:17:11] INFO: clockwork moved 'unmonitored' to 'init'
I [2014-07-04 09:17:11] INFO: clockwork [trigger] process is not running (ProcessRunning)
I [2014-07-04 09:17:11] INFO: clockwork move 'init' to 'start'
I [2014-07-04 09:17:11] INFO: clockwork before_start: no pid file to delete (CleanPidFile)
I [2014-07-04 09:17:11] INFO: clockwork start: bundle exec clockworkd -c /home/wangxiantong/projects/tao800_fire/clock.rb -l --pid-dir=/home/wangxiantong/projects/tao800_fire/tmp --log-dir=/home/wangxiantong/projects/tao800_fire/log start
W [2014-07-04 09:17:11] WARN: clockwork start command exited with non-zero code = 1
I [2014-07-04 09:17:11] INFO: clockwork moved 'init' to 'start'
I [2014-07-04 09:17:11] INFO: clockwork [ok] process is not running (ProcessRunning)
I [2014-07-04 09:17:11] INFO: clockwork [ok] tries within bounds [1/5] (Tries)
I [2014-07-04 09:17:16] INFO: clockwork [ok] process is not running (ProcessRunning)
I [2014-07-04 09:17:16] INFO: clockwork [ok] tries within bounds [2/5] (Tries)
I [2014-07-04 09:17:21] INFO: clockwork [ok] process is not running (ProcessRunning)
I [2014-07-04 09:17:21] INFO: clockwork [ok] tries within bounds [3/5] (Tries)
I [2014-07-04 09:17:26] INFO: clockwork [ok] process is not running (ProcessRunning)
I [2014-07-04 09:17:26] INFO: clockwork [ok] tries within bounds [4/5] (Tries)
Running standalone:
bundle exec clockworkd -c /home/wangxiantong/projects/tao800_fire/clock.rb -l --pid-dir=/home/wangxiantong/projects/tao800_fire/tmp --log-dir=/home/wangxiantong/projects/tao800_fire/log start
output:
clockworkd.clock: pid file: /home/wangxiantong/projects/tao800_fire/tmp/clockworkd.clock.pid
clockworkd.clock: output log file: /home/wangxiantong/projects/tao800_fire/log/clockworkd.clock.output
How are you starting god? What directory are you in when you start god? What user is god being started with? What user are you starting your manual run with? Are you using a ruby switcher like RVM or rbenv?
start god in rails project root dir: god -c god/clockwork.god -D. user: wangxiantong. Use RVM and bundle to install all gems including god and clockwork
RVM is a complication that I choose not to deal with on production servers. On my servers there is only one system Ruby. This could be the root of your issue, particularly but not limited to if you are switching gemsets.
RVM is dependent on monitoring the CD commands inside the bash shell. Setting the job dir like follows is likely insufficient.
w.dir = RAILS_ROOT
Additionally the user who ran GOD MUST have sourced ~/.bash_profile OR alternatively loaded RVM into the environment already.
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
if god is running as a different user than your application all bets are off, I don't even know if a system installation of RVM is going to help you.
using the CD invocation method inside the shell may yield better results, but this isn't how I would choose to run a production server.
base_cmd = "cd #{RAILS_ROOT} && bundle exec clockworkd ...
My suggestion is to run your config which looks reasonable, but remove RVM and install a suitable system Ruby.
@donovanbray :+1: , rvm in production is crazy, rbenv is much better because not using bash functions, only env variables.
+1 for rbenv in production