2011-10-29 17 views
3

我想运行一个ruby mongrel脚本作为我的供应系统(CHEF)的最后一步。因此,我写了下面的条目是一个暴发户.conf文件:厨师食谱:Upstart daemon不以Ruby开头

#!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并没有改变任何东西。

但是,如果我手动执行脚本,我可以启动服务器

[email protected]:/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' 

我对流浪运行与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 

任何想法? 谢谢

回答

2

问题是,您的Upstart配置在Vagrant完成设置代码的共享文件夹的安装之前运行。当你从命令行手动运行它后,它已经被挂载。

我不知道解决的办法是什么 - 如果你能勾引导过程,其中这个发生时,你可以发出一个事件,如:

initctl emit vagrant-mounted 

您新贵的配置可能等待

start on vagrant-mounted 
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 
.... 
0

至少在Ubuntu 12.04,你可以等待“安装”,这是由mountall将工作emited信号。

start on mounted 

上面的节应该与Vagrant共享文件夹一起使用。