RVM与瘦用户,root用户和本地用户 [英] RVM and thin, root vs. local user
问题描述
因此,我试图变得精简以在RVM中作为服务运行。 瘦安装
后,我手动更新了 /etc/init.d/thin
以使用 su-用户
运行config命令时,使Thin以本地用户而不是root用户身份运行。
现在,当我尝试使用 sudo服务瘦启动
时,它似乎正在尝试使用非RVM版本的Ruby(最初安装在包装盒上的1.8.7版)可以实际执行命令。我在非RVM版本上进行了 gem安装精简
,然后得到了未初始化的常量Bundler
消息— Bundler仅安装在RVM gem中,而不安装在系统gem中。看来我无法设置RVM环境(即使我的RVM启动脚本位于〜/ .bashrc中,然后又包含在〜/ .bash_profile中)。
<我想做的只是使用RVM环境而不是系统环境作为服务运行。这有可能吗?我是否应该放弃并承担以root用户身份运行所有内容的最终罪过?
感谢您的帮助!
RVM带有一个方便的包装生成器,该生成器为init.d脚本创建了一个中间加载器。这使您可以使用特定的Ruby版本和gemset加载服务。我这样使用它(安装瘦宝石后):
1-为瘦创建init.d条目
sudo薄安装
2-设置一些默认值
sudo /usr/sbin/update-rc.d -f薄默认值
3-生成您的Rails应用程序的启动配置
sudo Thin config -C /etc/thin/<appname>.yml -c / var / rails /< ; appdir> --servers 4 -e生产
4-生成rvm包装器脚本
rvm包装器< rubyversion> @< gemset>启动瘦
5-如果使用的是全局gemset,则只需使用
rvm包装器ruby-1.9.2-p125启动瘦
6-编辑Thin Init
sudo nano /etc/init.d/thin
7-更改原始加载程序
DAEMON = / usr / local / rvm / gems / ruby-< rubyversion> ;-< rubyrevision> @< gemset> / bin / thin
8-而是指向rvm包装器
DAEMON = / usr / local / bin / bootup_thin
9-启动
sudo服务瘦启动
如果您要运行多个应用程序,只需为每个应用程序生成一个启动配置yml文件;引导时,将解析/ etc / thin /中的所有yml文件。此处更多信息:
http:// wiki.rubyonrails.org/deployment/nginx-thin?rev=1233246014 nb:这是链接到修订,最新版本已被编辑为空。考虑查看链接中没有?rev = ...
的链接,当前版本可能已恢复,并且可能是最新版本。
HTH
2013奖金编辑
虽然我不再在生产中使用RVM,但薄型仍然是我的生产服务器选择,并且我仍然使用上面的步骤1-3开始。但是它生成的默认配置可以进行一些调整,以下是我的一些调整:
设置用户&精简运行的组为:
用户:www-data
组:www-data
删除端口配置并改为使用套接字(快一点):
#端口:3000
套接字:tmp / sockets /< appname> .sock
告诉瘦重启实例一个接一个,而不是先关闭它们再重新启动(滚动重新启动):
onebyone:真
让服务器处理一个标签,以帮助识别它们(在ps aux等中):
标签:< appname>
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!
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
sudo thin install
2 - set up some defaults
sudo /usr/sbin/update-rc.d -f thin defaults
3 - generate boot config for your rails app
sudo thin config -C /etc/thin/<appname>.yml -c /var/rails/<appdir> --servers 4 -e production
4 - generate rvm wrapper script
rvm wrapper <rubyversion>@<gemset> bootup thin
5 - If you're using a global gemset, you can just use
rvm wrapper ruby-1.9.2-p125 bootup thin
6 - edit thin init
sudo nano /etc/init.d/thin
7 - change the original loader
DAEMON=/usr/local/rvm/gems/ruby-<rubyversion>-<rubyrevision>@<gemset>/bin/thin
8 - to point to the rvm wrapper instead
DAEMON=/usr/local/bin/bootup_thin
9 - start it up
sudo service thin start
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:
user: www-data
group: www-data
Remove the port config and switch to using sockets instead (a little faster):
# port: 3000
socket: tmp/sockets/<appname>.sock
Tell thin to restart instances one by one, instead of shutting them all down before starting up again (rolling restart):
onebyone: true
Give the server processes a "tag" to help identify them (in ps aux etc):
tag: <appname>
这篇关于RVM与瘦用户,root用户和本地用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!