【发布时间】:2011-12-29 11:41:34
【问题描述】:
好吧,这正在融化我的大脑。这可能与我不太了解 Upstart 的事实有关。提前很抱歉问了这么长的问题。
我正在尝试使用 Upstart 来管理 Rails 应用的 Unicorn 主进程。这是我目前的/etc/init/app.conf:
description "app"
start on runlevel [2]
stop on runlevel [016]
console owner
# expect daemon
script
APP_ROOT=/home/deploy/app
PATH=/home/deploy/.rbenv/shims:/home/deploy/.rbenv/bin:$PATH
$APP_ROOT/bin/unicorn -c $APP_ROOT/config/unicorn.rb -E production # >> /tmp/upstart.log 2>&1
end script
# respawn
效果很好 - Unicorns 开始时很棒。不好的是检测到的 PID 不是 Unicorn master 的,它是一个sh 进程。这本身并没有那么糟糕——如果我没有使用自动独角兽零停机部署策略的话。因为在我将-USR2 发送给我的独角兽主人后不久,一个新的主人产生了,而旧的主人死了……sh 进程也是如此。所以 Upstart 认为我的工作已经死了,我不能再用 restart 重新启动它,或者如果我想用 stop 停止它。
我玩过配置文件,尝试将 -D 添加到 Unicorn 行(如下所示:$APP_ROOT/bin/unicorn -c $APP_ROOT/config/unicorn.rb -E production -D)以守护 Unicorn,我添加了 expect daemon 行,但这也不起作用.我也试过expect fork。所有这些事情的各种组合都可能导致start 和stop 挂起,然后Upstart 对工作的状态感到非常困惑。那我得重启机器修复一下。
我认为 Upstart 在检测 Unicorn 何时/是否分叉时遇到问题,因为我在我的 $APP_ROOT/bin/unicorn 脚本中使用了 rbenv + ruby-local-exec shebang。这里是:
#!/usr/bin/env ruby-local-exec
#
# This file was generated by Bundler.
#
# The application 'unicorn' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
require 'rubygems'
require 'bundler/setup'
load Gem.bin_path('unicorn', 'unicorn')
此外,ruby-local-exec 脚本如下所示:
#!/usr/bin/env bash
#
# `ruby-local-exec` is a drop-in replacement for the standard Ruby
# shebang line:
#
# #!/usr/bin/env ruby-local-exec
#
# Use it for scripts inside a project with an `.rbenv-version`
# file. When you run the scripts, they'll use the project-specified
# Ruby version, regardless of what directory they're run from. Useful
# for e.g. running project tasks in cron scripts without needing to
# `cd` into the project first.
set -e
export RBENV_DIR="${1%/*}"
exec ruby "$@"
所以我很担心里面有一个exec。它启动了一个 Ruby 进程,该进程启动了 Unicorn,它可能会或可能不会自行守护进程,这一切都首先发生在 sh 进程中......这让我严重怀疑 Upstart 跟踪所有这些的能力废话。
我正在尝试做的事情是否可能?据我了解,Upstart 中的expect 节只能被告知(通过daemon 或fork)预计最多有两个分叉。
【问题讨论】:
标签: ruby-on-rails ruby unicorn upstart