我有一些应用程序在ruby 1.9.2上运行rails 3,并使用nginx + passenger部署在Ubuntu 10.04 LTS机器上。现在,我需要添加一个在ruby 1.8.7(REE)和Rails 2上运行的新应用程序。我已经完成了使用RVM,Passenger Standalone和反向代理的操作。

问题是,每次必须重新启动服务器(例如,安装安全更新)时,都必须手动启动“乘客独立”。

有没有办法自动启动它?有人告诉我使用Monit或God,但我无法编写适用于“乘客独立版”的正确配方。我在God和RVM上也遇到了一些问题,因此,如果您有不使用God的解决方案,或者您知道如何正确配置God/Rvm,那就更好了。

最佳答案

这就是我的工作。使用Upstart(Ubuntu 10.04)启动旅客守护程序

我的环境使用带有ruby 1.9.2和apache的rvm和我的rails应用程序通过capistrano进行部署

# Upstart: /etc/init/service_name.conf
description "start passenger stand-alone"
author "Me <[email protected]>"

# Stanzas
#
# Stanzas control when and how a process is started and stopped
# See a list of stanzas here: http://upstart.ubuntu.com/wiki/Stanzas#respawn

# When to start the service
start on started mysql

# When to stop the service
stop on runlevel [016]

# Automatically restart process if crashed
respawn

# Essentially lets upstart know the process will detach itself to the background
expect fork

# Run before process
pre-start script
end script

# Start the process
script
        cd /var/path/to/app/staging/current
        sh HOME=/home/deploy /usr/local/rvm/gems/ruby-1.9.2-p136@appname/gems/passenger-3.0.7/bin/passenger start --user 'deploy' -p '5000' -a '127.0.0.1' -e 'production'
end script

和apache配置:
<VirtualHost *:80>
    ServerName myapp.com

    PassengerEnabled off

                <Proxy *>
                        Order deny,allow
                        Allow from all
                </Proxy>

    ProxyPass / http://127.0.0.1:5000/
    ProxyPassReverse / http://127.0.0.1:5000/

</VirtualHost>

Upstart并未设置乘客所依赖的ENV ['HOME'],因此我们在执行乘客命令时必须传递它。除此之外,它非常简单。

调试说明:https://serverfault.com/questions/114052/logging-a-daemons-output-with-upstart(将>> /tmp/upstart.log 2>&1之类的内容添加到脚本块的第二行)

希望这可以帮助。

10-08 16:09