RVM 和瘦、root 与本地用户

发布于 2024-09-09 06:38:24 字数 549 浏览 5 评论 0原文

所以我正在尝试精简以作为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

我是男神闪亮亮 2024-09-16 06:38:24

RVM 附带了一个方便的包装生成器,可以为 init.d 脚本创建中间加载器。这允许您使用特定的 Ruby 版本和 gemset 加载服务。我这样使用它(安装thin gem后):

1 - 为thin创建init.d条目

sudo thin install 

2 - 设置一些默认值

sudo /usr/sbin/update-rc.d -f thin defaults 

3 - 为rails应用程序生成启动配置

sudo thin config -C /etc/thin/<appname>.yml -c /var/rails/<appdir> --servers 4 -e production

4 - 生成rvm包装脚本

rvm wrapper <rubyversion>@<gemset> bootup thin

5 - 如果您使用一个全局 gemset,你可以只使用

rvm wrapper ruby-1.9.2-p125 bootup thin

6 - 编辑瘦初始化

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 service thin start

如果你运行多个应用程序,只需生成一个启动配置 yml 文件对于每一个;当启动 Thin 时,/etc/thin/ 中的所有 yml 文件都会被解析。更多信息请参见:

http://wiki.rubyonrails.org/deployment/nginx-thin ?rev=1233246014 nb:这是链接到修订版,最新版本已被编辑为空。考虑查看网址中不带 ?rev=... 的链接,当前版本可能会回来,并且可能会更新。

HTH

2013 BONUS EDIT

虽然我不再使用RVM 在生产中,thin 仍然是我选择的生产服务器,并且我仍然使用上面的步骤 1-3 来开始。但它生成的默认配置可以进行一些调整,以下是我的一些调整

:瘦运行的组:

user: www-data
group: www-data

删除端口配置并切换到使用套接字(更快一点):

# port: 3000
socket: tmp/sockets/<appname>.sock

告诉瘦一个一个地重新启动实例,而不是在再次启动之前将它们全部关闭(滚动重新启动):

onebyone: true

给服务器进程帮助识别它们的“标签”(在 ps aux 等中):

tag: <appname>

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>
随遇而安 2024-09-16 06:38:24

一个有望节省一些时间的附录:Ubuntu 可以使用 sudo 和环境变量做一些有趣的事情。如果常规 sudo 不起作用,请使用 rvmsudo(在 .rvm/bin 中):

rvmsudo thin install

rvmsudo update-rc.d -f thin defaults

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):

rvmsudo thin install

rvmsudo update-rc.d -f thin defaults
燕归巢 2024-09-16 06:38:24

一种好的做法可能是将应用程序置于服务中,而不是精简应用程序,以便能够在不同的环境中启动应用程序,例如 ruby​​ 1.8.7 myapp1.8.7 中的一个应用程序和 ruby​​ 1.9.2 myapp1.9.2 中的另一个应用程序

sudo nano /etc/init.d/myapp1.8.7

保留原始加载

DAEMON=/usr/local/rvm/gems/ruby-<rubyversion>-<rubyrevision>@<gemset>/bin/thin

程序start case place

$DAEMON -C /etc/thin/$NAME.yml start

并启动它

sudo service myapp1.8.7 start

对应用程序 myapp1.9.2 执行相同的操作,您将可以在混合环境中独立运行许多应用程序。

sudo service myapp1.9.2 start

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

sudo nano /etc/init.d/myapp1.8.7

KEEP the original loader

DAEMON=/usr/local/rvm/gems/ruby-<rubyversion>-<rubyrevision>@<gemset>/bin/thin

In start case place

$DAEMON -C /etc/thin/$NAME.yml start

and start it up

sudo service myapp1.8.7 start

Does the same thing with app myapp1.9.2 and you will can run many applications independently in mixed environments.

sudo service myapp1.9.2 start
初与友歌 2024-09-16 06:38:24

对于独立安装一个简单的解决方案,我为“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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文