问题描述
我正在研究上帝的脚本来监视我的独角兽.我从GitHub的示例脚本开始,并一直对其进行修改以匹配我的服务器配置.一旦神跑了,诸如god stop unicorn
和god restart unicorn
之类的命令就可以正常工作.
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.
但是,god start unicorn
会导致WARN: unicorn start command exited with non-zero code = 1
.奇怪的是,如果我直接从配置文件中复制启动脚本,它将像全新的野马一样直接启动.
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.
这是我的启动命令:
/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?
推荐答案
我还没有使用独角兽作为应用程序服务器,但以前我一直使用上帝来进行监控.
I haven't used unicorn as an app server, but I've used god for monitoring before.
如果我没记错的话,当您启动God并提供配置文件时,它将自动启动您告诉其观看的内容.独角兽可能已经在运行,这就是它引发错误的原因.
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.
一旦开始了上帝,请运行god status
进行检查.如果不是这种情况,您可以在命令行上检查命令的退出状态是什么:
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 $?;
该回显将显示最后一条命令的退出状态.如果为零,则最后一条命令未报告任何错误.尝试连续两次启动独角兽,我希望它第二次返回1,因为它已经在运行.
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.
包括评论中的实际解决方案,因为这似乎很受欢迎:
including the actual solution from comments, as this seems to be a popular response:
如果您的进程需要以特定用户身份运行,则可以设置一个显式用户和组.
You can set an explicit user and group if your process requires to be run as a specific user.
God.watch do |w|
w.uid = 'root'
w.gid = 'root'
# remainder of config
end
这篇关于用上帝监视独角兽-以非零代码= 1开始退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!