RVM 和瘦、root 与本地用户
所以我正在尝试精简以作为 RVM 的服务运行。在精简安装
之后,我手动更新了/etc/init.d/thin
以在运行配置命令时使用su - user
,以便精简以本地用户身份运行,而不是 root。到目前为止,一切都很好。
现在,当我尝试 sudo service Thin start 时,它看起来像是在尝试使用非 RVM 版本的 Ruby(1.8.7,安装在盒子上开始)来实际执行命令。我在非 RVM 版本上执行了 gem install Thin
,然后收到一条 未初始化常量 Bundler
消息 — Bundler 仅安装在 RVM gems 中,而不安装在系统 gems 中。看起来我无法设置 RVM 环境(即使我的 RVM 启动脚本位于 ~/.bashrc 中,然后该脚本包含在 ~/.bash_profile 中)。
我想要做的就是使用 RVM 环境(而不是系统环境)作为服务来瘦运行。这可能吗?我是否应该放弃并犯下以 root 身份运行一切的终极罪恶?在这一点上这是非常诱人的。
感谢您的帮助!
So I'm trying to get thin to run as a service with RVM. After a thin install
I manually updated /etc/init.d/thin
to use an su - user
when running the config command so that thin was running as a local user, rather than root. So far so good.
Now, when I try to sudo service thin start
it looks like it's trying to use the non-RVM version of Ruby (1.8.7 which was installed on the box to start with) to actually execute the command. I did a gem install thin
on the non-RVM version, which then gets me a uninitialized constant Bundler
message—Bundler is only installed in the RVM gems, not the system gems. It looks like I can't get the RVM environment set up (even though my RVM startup script is in ~/.bashrc which is then included in ~/.bash_profile).
All I want to do is run thin as a service using the RVM environment, not the system environment. Is this even possible? Should I just give up and commit the ultimate sin of running everything as root? It's very tempting at this point.
Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
RVM 附带了一个方便的包装生成器,可以为 init.d 脚本创建中间加载器。这允许您使用特定的 Ruby 版本和 gemset 加载服务。我这样使用它(安装thin gem后):
1 - 为thin创建init.d条目
2 - 设置一些默认值
3 - 为rails应用程序生成启动配置
4 - 生成rvm包装脚本
5 - 如果您使用一个全局 gemset,你可以只使用
6 - 编辑瘦初始化
7 - 更改原始加载程序
8 - 指向 rvm 包装器
9 - 启动它
如果你运行多个应用程序,只需生成一个启动配置 yml 文件对于每一个;当启动 Thin 时,/etc/thin/ 中的所有 yml 文件都会被解析。更多信息请参见:
http://wiki.rubyonrails.org/deployment/nginx-thin ?rev=1233246014 nb:这是链接到修订版,最新版本已被编辑为空。考虑查看网址中不带
?rev=...
的链接,当前版本可能会回来,并且可能会更新。HTH
2013 BONUS EDIT
虽然我不再使用RVM 在生产中,thin 仍然是我选择的生产服务器,并且我仍然使用上面的步骤 1-3 来开始。但它生成的默认配置可以进行一些调整,以下是我的一些调整
:瘦运行的组:
删除端口配置并切换到使用套接字(更快一点):
告诉瘦一个一个地重新启动实例,而不是在再次启动之前将它们全部关闭(滚动重新启动):
给服务器进程帮助识别它们的“标签”(在 ps aux 等中):
RVM comes with a handy wrapper generator that creates an intermediary loader for an init.d script. This allows you to load a service using a particular Ruby version and gemset. I use it like this (after installing the thin gem):
1 - create init.d entry for thin
2 - set up some defaults
3 - generate boot config for your rails app
4 - generate rvm wrapper script
5 - If you're using a global gemset, you can just use
6 - edit thin init
7 - change the original loader
8 - to point to the rvm wrapper instead
9 - start it up
If you're running more than one app, just generate a boot config yml file for each one; when booting thin all yml files in /etc/thin/ are parsed. More info here:
http://wiki.rubyonrails.org/deployment/nginx-thin?rev=1233246014 nb: This is linking to a revision, the most current version has been edited to be empty. Consider looking at the link without the
?rev=...
in the url, the current version may be back and potentially more up to date.HTH
2013 BONUS EDIT
While I no longer use RVM in production, thin is still my production server of choice, and I still use steps 1-3 above to get started. But the default configuration it generates can do with a few tweaks, here are some of mine:
Set the user & group that thin runs as:
Remove the port config and switch to using sockets instead (a little faster):
Tell thin to restart instances one by one, instead of shutting them all down before starting up again (rolling restart):
Give the server processes a "tag" to help identify them (in ps aux etc):
一个有望节省一些时间的附录:Ubuntu 可以使用 sudo 和环境变量做一些有趣的事情。如果常规 sudo 不起作用,请使用 rvmsudo(在 .rvm/bin 中):
One addendum that will hopefully save some time: Ubuntu can do funny things with sudo and environment variables. If regular sudo isn't working, use rvmsudo (in .rvm/bin):
一种好的做法可能是将应用程序置于服务中,而不是精简应用程序,以便能够在不同的环境中启动应用程序,例如 ruby 1.8.7 myapp1.8.7 中的一个应用程序和 ruby 1.9.2 myapp1.9.2 中的另一个应用程序
保留原始加载
程序start case place
并启动它
对应用程序 myapp1.9.2 执行相同的操作,您将可以在混合环境中独立运行许多应用程序。
A good practice might be to put the application in service instead thin as to be able to start applications in different environments such one app in ruby 1.8.7 myapp1.8.7 and another app in ruby 1.9.2 myapp1.9.2
KEEP the original loader
In start case place
and start it up
Does the same thing with app myapp1.9.2 and you will can run many applications independently in mixed environments.
对于独立安装一个简单的解决方案,我为“rvm 要求”的用户添加了 root 权限,然后使用 visudo 用户名 ALL=(ALL:ALL) ALL
https://www.digitalocean.com/ Community/articles/how-to-add-delete-and-grant-sudo-privileges-to-users-on-a-debian-vps
然后您可能会遇到对 /usr 的读/写访问权限的问题/local/rvm
我更改了权限,以便所有用户都可以读/写/执行;
as root 'chomod a+xwr /usr/local/rvm/'
更新 GEMS 时,您将从 RVM 收到有关所有用户对此文件夹具有读/写/执行访问权限的警告
for a standalone installation a simple solution, i added the root privileges to the user for 'rvm requirements' and then removed the privileges using visudo username ALL=(ALL:ALL) ALL
https://www.digitalocean.com/community/articles/how-to-add-delete-and-grant-sudo-privileges-to-users-on-a-debian-vps
Your likely then to have the problem with read/write access to /usr/local/rvm
I changed permissions so all users could read/write/execute;
as root 'chomod a+xwr /usr/local/rvm/'
You will get warnings from RVM about all users having read/write/execute access to this folder when updating GEMS