我无法弄清楚如何让上帝重新启动 resque。
我在 Ubuntu 10.04.3 LTS Linode 切片上有一个 Rails 3.2.2 堆栈。其运行系统 Ruby 1.9.3-p194(无 RVM)。
有一个上帝 init.d 服务,/etc/init.d/god-service
其中包含:
CONF_DIR=/etc/god
GOD_BIN=/var/www/myapp.com/shared/bundle/ruby/1.9.1/bin/god
RUBY_BIN=/usr/local/bin/ruby
RETVAL=0
# Go no further if config directory is missing.
[ -d "$CONF_DIR" ] || exit 0
case "$1" in
start)
# Create pid directory
$RUBY_BIN $GOD_BIN -c $CONF_DIR/master.conf
RETVAL=$?
;;
stop)
$RUBY_BIN $GOD_BIN terminate
RETVAL=$?
;;
restart)
$RUBY_BIN $GOD_BIN terminate
$RUBY_BIN $GOD_BIN -c $CONF_DIR/master.conf
RETVAL=$?
;;
status)
$RUBY_BIN $GOD_BIN status
RETVAL=$?
;;
*)
echo "Usage: god {start|stop|restart|status}"
exit 1
;;
esac
exit $RETVAL
master.conf
在上面包含:
load "/var/www/myapp.com/current/config/resque.god"
resque.god
在上面包含:
APP_ROOT = "/var/www/myapp.com/current"
God.log_file = "/var/www/myapp.com/shared/log/god.log"
God.watch do |w|
w.name = 'resque'
w.interval = 30.seconds
w.dir = File.expand_path(File.join(File.dirname(__FILE__),'..'))
w.start = "RAILS_ENV=production bundle exec rake resque:work QUEUE=*"
w.uid = "deploy"
w.gid = "deploy"
w.start_grace = 10.seconds
w.log = File.expand_path(File.join(File.dirname(__FILE__), '..','log','resque-worker.log'))
# restart if memory gets too high
w.transition(:up, :restart) do |on|
on.condition(:memory_usage) do |c|
c.above = 200.megabytes
c.times = 2
end
end
# determine the state on startup
w.transition(:init, { true => :up, false => :start }) do |on|
on.condition(:process_running) do |c|
c.running = true
end
end
# determine when process has finished starting
w.transition([:start, :restart], :up) do |on|
on.condition(:process_running) do |c|
c.running = true
c.interval = 5.seconds
end
# failsafe
on.condition(:tries) do |c|
c.times = 5
c.transition = :start
c.interval = 5.seconds
end
end
# start if process is not running
w.transition(:up, :start) do |on|
on.condition(:process_running) do |c|
c.running = false
end
end
end
在deploy.rb
我有一个重新加载任务:
task :reload_god_config do
run "god stop resque"
run "god load #{File.join(deploy_to, 'current', 'config', 'resque.god')}"
run "god start resque"
end
问题是无论我是部署还是god (stop|start|restart|status) resque
手动运行,我都会收到错误消息:
The server is not available (or you do not have permissions to access it)
我尝试安装god
到系统 gem 并指向它god-service
:
GOD_BIN=/usr/local/bin/god
但god start rescue
给出了同样的错误。
但是,我可以通过以下方式启动服务:
sudo /etc/init.d/god-service start
root
因此,我认为,这可能是一个权限问题,可能与 init.d 服务归用户所有,并且 God 由用户从捆绑包中运行的事实有关deploy
。
解决这个问题的最佳方法是什么?