这是我的工作。使用 Upstart (Ubuntu 10.04) 启动乘客守护进程
我的环境使用 rvm 和 ruby 1.9.2 和 apache,我的 rails 应用程序是通过 capistrano 部署的
# Upstart: /etc/init/service_name.conf
description "start passenger stand-alone"
author "Me <me@myself.am>"
# 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>> /tmp/upstart.log 2>&1
://serverfault.com/questions/114052/logging-a-daemons-output-with-upstart(在脚本块的第二行附加类似的内容)
希望这可以帮助。