厨师食谱:Upstart守护进程不是以Ruby开头的

时间:2011-10-29 10:25:37

标签: ruby mongrel chef vagrant upstart

我想运行ruby mongrel脚本作为我的配置系统(CHEF)的最后一步。因此,我写了一个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'

我使用RVM和Ruby 1.8.7,Rubygems 1.3.7运行Vagrant。引导配方是:

[...]
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 个答案:

答案 0 :(得分:2)

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

我不确定解决方案是什么 - 如果你可以在启动过程中挂钩,你可以发出一个事件,例如:

initctl emit vagrant-mounted

您的Upstart配置可以等待

start on vagrant-mounted

答案 1 :(得分: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
....

答案 2 :(得分:0)

至少在Ubuntu 12.04中,您可以等待mountall作业发出的“已安装”信号。

start on mounted

上面的节应该适用于Vagrant共享文件夹。