监控RVM + OSX / Linux 上的瘦身
经过几个小时的尝试(也尝试了 God 和 Bluepill)后,我决定在这里问我的问题,因为我完全不知道如何解决这个问题。
我有一个 Rails 应用程序。我想使用 Thin 作为我的应用程序服务器。我想使用 Monit 来监控我的 Thin 实例。我使用 RVM 作为本地用户管理我的 Ruby 版本。
我设置了以下 monit 文件,它可能会做我想要它做的事情,但没有:
check process thin-81
with pidfile /Users/Michael/Desktop/myapp/tmp/pids/thin.81.pid
start program = "/Users/Michael/.rvm/gems/ruby-1.9.2-p180/bin/thin start -c /Users/Michael/Desktop/myapp -e production -p 81 -d -P tmp/pids/thin.81.pid"
stop program = "/Users/Michael/.rvm/gems/ruby-1.9.2-p180/bin/thin stop -c /Users/Michael/Desktop/myapp -P tmp/pids/thin.81.pid"
if totalmem is greater than 150.0 MB for 2 cycles then restart
如果我只是将 start 程序
复制/粘贴到命令行(Monit 之外)有用。对于随后停止 Thin 实例的停止程序
也是如此。然而,通过 Monit 运行它似乎不起作用。
在 -v
详细模式下运行它会产生以下结果:
monit: pidfile '/Users/Michael/Desktop/myapp/tmp/pids/thin.81.pid' does not exist
这使我相信 Thin 永远不会初始化。 Monit 是否以 root
身份运行?因为如果确实如此,那么显然不会安装正确的 gem,因为我使用的是 RVM 而不是“系统”Ruby。我目前使用的是 OSX(但最终会部署到 Linux) - 有谁知道这可能是什么原因?如果 Monit 是通过 root 运行的,我怎样才能让它使用 RVM 呢?或者我可以告诉 Monit 以 Michael:staff
的身份执行启动/停止程序(我假设它会在 OSX 上?)
非常感谢任何帮助!
After trying for hours (and also trying God and Bluepill) I decided to ask my question here because I am completely clueless how to solve this issue.
I have a Rails app. I want to use Thin as my app server. I want to use Monit to monitor my Thin instances. I use RVM to manage my Ruby versions as my local user.
I have the following monit file set up that would assumably do what I want it to do, but doesn't:
check process thin-81
with pidfile /Users/Michael/Desktop/myapp/tmp/pids/thin.81.pid
start program = "/Users/Michael/.rvm/gems/ruby-1.9.2-p180/bin/thin start -c /Users/Michael/Desktop/myapp -e production -p 81 -d -P tmp/pids/thin.81.pid"
stop program = "/Users/Michael/.rvm/gems/ruby-1.9.2-p180/bin/thin stop -c /Users/Michael/Desktop/myapp -P tmp/pids/thin.81.pid"
if totalmem is greater than 150.0 MB for 2 cycles then restart
If I simply copy/paste the start program
in to the command line (outside of Monit) it works. Same goes for the stop program
to afterwards stop the Thin instance. Running it via Monit however, does not seem to work.
Running it in -v
verbose mode yields the following:
monit: pidfile '/Users/Michael/Desktop/myapp/tmp/pids/thin.81.pid' does not exist
Which leads me to believe that Thin never initializes. Does Monit run as root
or something? Cause if it does then it obviously won't have the correct gems installed since I'm using RVM and not the "system" Ruby. I am currently on OSX (but will deploy to Linux eventually) - does anyone know what the cause of this might be? And if Monit is run via root, how could I make it use RVM regardless? Or could I tell Monit to execute the start/stop programs as Michael:staff
(I assume it would be on OSX?)
Any help is much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
monit 会清除环境,并且不会为您的命令运行 shell(更不用说交互式 shell)。我发现我必须做类似的事情:
作为 monit start 命令。
monit clears out the environment and also doesn't run a shell for your command (let alone an interactive one). I find I have to do something like:
as the monit start command.
我在 RVM google 组中找到的另一个选项如下:
su - user 将用户的 shell 作为登录 shell 运行,因此如果
用户的 shell 是 bash,它将导致 ~/.bash_profile 运行,因此
环境变量应该与该用户之后的环境变量相同
登录。
我们需要 su 的路径,否则,monitrc 将无法找到 su 可执行文件。
another option which I found in the RVM google group is as follows:
su - user runs the user's shell as a login shell, so if the
user's shell is bash, it will cause ~/.bash_profile to be run so the
environment variables should be the same as just after that user
logged in.
We need the path for su, otherwise, monitrc would not able to find the su executable.
更好的方法是使用 RVM 包装器为 Thin 创建自定义可执行文件。它将创建正确的环境变量以使用正确的 ruby 和 gems,然后启动瘦。在此处阅读有关与 god 一起使用它的更多信息:https://rvm.io/integration/god/ 。它应该与 monit 工作相同
要创建包装器:
rvm 包装器 ruby@gemset bootup slim
然后更改
启动程序
和停止程序
以使用刚刚创建的可执行文件。A better way would be to use an RVM wrapper to create a custom executable for thin. It will create the correct environment variables to use the right ruby and gems, and then launch thin. Read more about it using it with god here : https://rvm.io/integration/god/. It should work the same with monit
To create the wrapper:
rvm wrapper ruby@gemset bootup thin
Then change
start program
andstop program
to use the executable you just created.