Chef食谱:使用Ruby时Upstart守护进程无法启动

3
我想在我的自动化部署系统(CHEF)的最后一步运行一个 Ruby Mongrel 脚本。因此,我编写了一个 Upstart .conf 文件,其中包含以下条目:
#!upstart
description "mongrel server"
author      "daniele"

start on startup
stop on shutdown

# 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 /vagrant/trunk
   /bin/sh /vagrant/trunk/script/server -p 3000 >> /home/vagrant/log.txt
end script

然而log.txt文件为空,运行netstat -an | grep 3000没有任何显示。我认为脚本不可执行,但是运行chmod也没有改变什么。
然而,如果我手动执行脚本,我可以启动服务器。
vagrant@ubuntu10:/vagrant/trunk$ ./script/server 
=> Booting Mongrel
=> Rails 2.3.4 application starting on http://0.0.0.0:3000
/usr/local/rvm/gems/ruby-1.8.7-p352/gems/rails-2.3.4/lib/rails/gem_dependency.rb:119:Warning:Gem::Dependency#version_requirements is deprecated and will be removed on or after August 2010.  Use #requirement
=> Call with -d to detach
=> Ctrl-C to shutdown server

脚本的内容是:

#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/server'

我使用Vagrant、RVM和Ruby 1.8.7、Rubygems 1.3.7进行运行。引导配方如下:

[...]
template "mongrel.upstart.conf" do
   path "/etc/init/mongrel.conf"
   source "mongrel.upstart.conf.erb"
   mode 0644
   owner "root"
   group "root"
end

service "mongrel" do
   provider Chef::Provider::Service::Upstart
   supports :restart => true, :start => true, :stop => true
   action [:enable, :start]
end

任何想法吗?谢谢。
3个回答

2
问题在于您的Upstart配置在Vagrant完成设置共享文件夹(即您的代码所在位置)之前运行。当您稍后从命令行手动运行它时,已经挂载了该文件夹。
我不确定解决方案是什么 - 如果您可以钩入此过程发生的引导过程,则可以发出事件,例如:
initctl emit vagrant-mounted

你的Upstart配置可以等待以下内容:
start on vagrant-mounted

0

至少在Ubuntu 12.04中,你可以等待由mountall工作发出的"mounted"信号。

start on mounted

上述段落应该适用于Vagrant共享文件夹。


0

我曾通过添加代码部分地解决了类似的问题

sleep 10

回到脚本。就像这样:

...
# Start the process
script
    sleep 10
    cd /vagrant/trunk
    /bin/sh /vagrant/trunk/script/server -p 3000 >> /home/vagrant/log.txt
end script
....

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接