无法将Thin服务器作为服务启动,RubyGems:找不到Thin。

5
我使用以下指令在Ubuntu 10.04.4上安装和配置Thin服务器作为服务,并配合Rails 3.2.3使用:

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

在应用程序根目录下,使用'thin start'命令可以正常运行Thin服务器。但是,当我尝试使用以下任意一条命令运行服务时:
service thin start
sudo service thin start
/etc/init.d/thin start
sudo /etc/init.d/thin start

I get the following error:

/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>'

这似乎不是路径问题,'which thin' 命令可以正确返回:

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

我已经验证了无论在哪里引用 **/bin/thin,它都存在。
我尝试使用“gem uninstall thin”、“gem install thin”重新安装 gem,但没有成功。
有人之前遇到过这个问题吗?我只找到了一个类似的问题:Cannot restart thin via remote machine
那个问题似乎只出现在 ssh 上,而我甚至无法在本地启动 thin 服务。
谢谢。

你正在遵循的指南是针对旧版本的Ubuntu,10.04已经改变了init脚本的工作方式。此外,为什么要使用/etc/init.d来运行thin,而不是使用thin -d呢? - CuriousMind
我正在尝试让它在启动时作为服务运行,我应该创建一个运行thin -d的sh文件并将其放置在某个位置以在启动时运行吗? - samJL
2个回答

5

从您的堆栈跟踪信息中看,您正在使用rvm,并且已将thin作为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 list来查找名称。包装器的名称将为bootup_thin,你可以通过bootup_thin来确认它是否使用了正确的rvm。在创建时可以随意命名。然后,你需要通过编辑thin脚本来进行修改。
sudo nano /etc/init.d/thin

将原始的 DAEMON 更改为
DAEMON=location_of_bootup_thin 

执行which bootup_thin应该会返回什么结果呢?然后您就可以启动服务了。

sudo service thin start

我希望您能从中受益。

2

似乎每个创业公司的工作都会加载它自己的 shell。因此,在尝试启动 thin 之前,请尝试加载 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中并运行:

$ sudo update-rc.d  thin_service defaults

最后,您可以通过简单地输入sudo start thin_servicesudo stop start_thin来进行测试,而不是重新启动。 如果这仍然不起作用,请尝试使用railsgems-bundler和rvm wrapper。 此外,请阅读rvm的部署最佳实践

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接