2011-10-29 22 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共享文件夾一起使用。