gpt4 book ai didi

ruby - Chef Recipe : Upstart daemon not starting with Ruby

转载 作者:数据小太阳 更新时间:2023-10-29 08:05:46 24 4
gpt4 key购买 nike

我想在配置系统 (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'

我使用 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

有什么想法吗?谢谢

最佳答案

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

我不确定解决方案是什么——如果您可以连接到发生这种情况的引导过程,您可以发出一个事件,例如:

initctl emit vagrant-mounted

您的 Upstart 配置可以等待

start on vagrant-mounted

关于ruby - Chef Recipe : Upstart daemon not starting with Ruby,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7938283/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com