部署Ruby + RVM和daemontools的问题

时间:2011-05-17 17:17:33

标签: ruby rvm

我在生产中使用daemontools来保持服务的活跃,并希望运行Ruby服务器,而不是Rails,没有RVM它运行良好但是使用RVM我有一些问题。

我的目标是通过root启动进程,使其删除root权限以获取另一个用户权限,然后使用RVM和指定的Ruby版本生成Ruby进程。

这是我到目前为止使用的运行脚本:

#!/bin/sh
exec 2>&1
cd /app/src
. /usr/local/rvm/scripts/rvm
rvm use 1.9.1-p378
exec setuidgid app_user ruby main.rb

此脚本有效但setuidgid存在一个主要问题:应用程序将由用户<x>和组<x>运行,并且仅由该组运行。如果用户在其他组中,则该过程将不具有其权限。

所以它引导我采用另一种方法:

#!/bin/sh
exec 2>&1
cd /app
exec sudo -u app_user rvm 1.9.1-p378 exec ruby main.rb

这个工作正常,除了它是由daemontools产生的RVM进程,当它收到一个不太好的SIGTERM时它没有反应。基本上它意味着服务无法手动重启,这是不好的。

1 个答案:

答案 0 :(得分:1)

我找到了答案但是看了rvms安装的rvmsudo脚本,这是一个正常运行的脚本:

#!/bin/sh
# redirect stderr to stdout
exec 2>&1

cd /app
# load rvm
. /usr/local/rvm/scripts/rvm

# select ruby version for this application
rvm use 1.9.1
# # depending on your configuration you may need to provide the absolute path to rvm, like that:
# /usr/local/bin/rvm use 1.9.1

# build the exec command line preserving the rvm environment
command="exec sudo -u app_user /usr/bin/env PATH='$PATH'"

[[ -n "${GEM_HOME:-}" ]] && command="${command} GEM_HOME='$GEM_HOME' "
[[ -n "${GEM_PATH:-}" ]] && command="${command} GEM_PATH='$GEM_PATH' "

# this is where your real command line goes
command="${command} ruby main.rb"

# run the application
eval "${command}"