无法启动瘦服务器作为服务,RubyGems:找不到瘦

时间:2012-04-30 20:19:51

标签: ruby-on-rails thin

我使用以下说明在Ubuntu 10.04.4上使用Rails 3.2.3安装和配置瘦服务器作为服务:

http://articles.slicehost.com/2008/5/6/ubuntu-hardy-thin-web-server-for-ruby

瘦服务器使用'thin start'

从应用程序根目录运行良好

但是,当我尝试使用以下任何命令运行服务时:

service thin start
sudo service thin start
/etc/init.d/thin start
sudo /etc/init.d/thin start

我收到以下错误:

/home/myuser/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find thin (>= 0) amongst [bigdecimal-1.1.0, io-console-0.3, json-1.5.4, minitest-2.5.1, rake-0.9.2.2, rdoc-3.9.4] (Gem::LoadError)
    from /home/myuser/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
    from /home/myuser/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems.rb:1210:in `gem'
    from /home/myuser/.rvm/gems/ruby-1.9.3-p125/bin/thin:18:in `<main>'

这似乎不是PATH的问题,'瘦'正确返回:

home/myuser/.rvm/gems/ruby-1.9.3-p125/bin/thin

我还验证了** / bin / thin的存在,只要它被引用

我尝试使用'gem uninstall thin'重新安装gem,'gem install thin'没有成功

以前有没有人经历过这个?我只发现了这个问题的另一个例子: Cannot restart thin via remote machine

这个问题似乎只是在ssh上,而我甚至无法在本地启动瘦服务

由于

2 个答案:

答案 0 :(得分:5)

由于它似乎来自你的堆栈跟踪,你使用的是rvm,而你使用的是精简版作为gem安装,你需要使用rvm包装器来使服务正常工作。首先删除服务端重新安装rvmsudo thin install而不是sudo thin install。您还应该在创建配置文件时使用rvmsudo thin config

创建包装器

rvm wrapper <your_rvm_ruby_version>@<your_rvm_gemset_in_use> bootup thin

您可以分别使用rvm listrvm gemset列表找到名称。包装器将具有名称bootup_thin,您可以使用bootup_thin确认它正在使用正确的rvm。您可以在创建时为其提供任何名称。然后你需要通过

编辑瘦脚本
sudo nano /etc/init.d/thin

将原始DAEMON更改为

DAEMON=location_of_bootup_thin 

哪个应该是which bootup_thin的结果。然后你就可以开始服务。

sudo service thin start

我希望这会有所帮助

答案 1 :(得分:2)

似乎每个启动作业都加载了自己的shell。所以,在尝试开始瘦身之前尝试加载rvm

#! /bin/sh
# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then

  # First try to load from a user install
  source "$HOME/.rvm/scripts/rvm"

elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then

  # Then try to load from a root install
  source "/usr/local/rvm/scripts/rvm"

else

  printf "ERROR: An RVM installation was not found.\n"

fi

rvm use 1.9.3
cd /path/to/your/application/code
bundle exec thin -d

将其放在/etc/init.d/thin_service&amp;运行

$ sudo update-rc.d  thin_service defaults

最后,您只需输入sudo start thin_service&amp; sudo stop start_thin而不是重新启动。如果仍然无效,请尝试使用railsgems-bundler和rvm包装器。另外,请阅读rvm's Deployment Best Practices