views:

108

answers:

1

Hello, I am working on a God script to monitor my Unicorns. I started with GitHub's examples script and have been modifying it to match my server configuration. Once God is running, commands such as god stop unicorn and god restart unicorn work just fine.

However, god start unicorn results in WARN: unicorn start command exited with non-zero code = 1. The weird part is that if I copy the start script directly from the config file, it starts right up like a brand new mustang.

This is my start command:

/usr/local/bin/unicorn_rails -c /home/my-linux-user/my-rails-app/config/unicorn.rb -E production -D

I have declared all paths as absolute in the config file. Any ideas what might be preventing this script from working?

+4  A: 

I haven't used unicorn as an app server, but I've used god for monitoring before.

If I remember rightly when you start god and give your config file, it automatically starts whatever you've told it to watch. Unicorn is probably already running, which is why it's throwing the error.

Check this by running god status once you've started god. If that's not the case you can check on the command line what the comand's exit status is:

/usr/local/bin/unicorn_rails -c /home/my-linux-user/my-rails-app/config/unicorn.rb -E production -D; echo $?;

that echo will print the exit status of the last command. If it's zero, the last command reported no errors. Try starting unicorn twice in a row, I expect the second time it'll return 1, because it's already running.

Jeremy
+1 for offering a plausible answer, not an attempt at wit.
Steven Sudit
Interesting... this was a really good suggestion. I used the echo addition to read the output of the start and stop commands when executed outside of god. They both exited with a value of `0`. However, when identical commands are executed by god, it exits with a value of `1`. All processes are supposed to start as root... both god and the unicorns. I wonder if there is an overarching permissions error here. Does that seem like a plausible answer?
mindtonic
yeah sounds like although god is running as root, it might be executing the command as another user? Looks like you can set the user god runs the commands as via: God.watch do |w| ... w.uid = 'root' w.gid = 'root' ... end
Jeremy
Jeremy ~ You are indeed a gentleman and a scholar. That was the solution!!
mindtonic