加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 使用thin作为服务运行Rails应用程序

发布时间:2020-12-17 01:58:15 所属栏目:百科 来源:网络整理
导读:我试图在我的Web服务器上运行瘦服务.运行“sudo thin install”后,thin在/etc/init.d/thin中创建了以下文件 #!/bin/shDAEMON=/usr/local/lib/ruby/gems/1.9.1/bin/thinSCRIPT_NAME=/etc/init.d/thinCONFIG_PATH=/etc/thin# Exit if the package is not insta
我试图在我的Web服务器上运行瘦服务.运行“sudo thin install”后,thin在/etc/init.d/thin中创建了以下文件

#!/bin/sh
DAEMON=/usr/local/lib/ruby/gems/1.9.1/bin/thin
SCRIPT_NAME=/etc/init.d/thin
CONFIG_PATH=/etc/thin

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

case "$1" in
  start)
        $DAEMON start --all $CONFIG_PATH
        ;;
  stop)
        $DAEMON stop --all $CONFIG_PATH
        ;;
  restart)
        $DAEMON restart --all $CONFIG_PATH
        ;;
  *)
        echo "Usage: $SCRIPT_NAME {start|stop|restart}" >&2
        exit 3
        ;;
esac

启动瘦服务时,将运行以下命令

thin start --all /etc/thin

??这将扫描所有yaml配置文件,定义如何为每个定义的应用程序运行瘦.这不起作用.

我在日志中看到:

/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.0/lib/bundler/runtime.rb:27:in `block in setup': You have already activated eventmachine 0.12.6,but your Gemfile requires eventmachine 0.12.11. Consider using bundle exec. (Gem::LoadError)
  from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.0/lib/bundler/spec_set.rb:12:in `block in each'
  from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.0/lib/bundler/spec_set.rb:12:in `each'
  from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.0/lib/bundler/spec_set.rb:12:in `each'
  from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.0/lib/bundler/runtime.rb:17:in `setup'
  from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.0/lib/bundler.rb:100:in `setup'
  from /srv/app/current/config/boot.rb:8:in `<top (required)>'
  from <internal:lib/rubygems/custom_require>:29:in `require'
  from <internal:lib/rubygems/custom_require>:29:in `require'
  from /srv/app/current/config/application.rb:1:in `<top (required)>'
  from <internal:lib/rubygems/custom_require>:29:in `require'
  from <internal:lib/rubygems/custom_require>:29:in `require'
  from /srv/app/current/config/environment.rb:2:in `<top (required)>'
  from <internal:lib/rubygems/custom_require>:29:in `require'
  from <internal:lib/rubygems/custom_require>:29:in `require'
  from /srv/app/current/config.ru:3:in `block in <main>'
  from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/builder.rb:46:in `instance_eval'
  from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/builder.rb:46:in `initialize'
  from /srv/app/current/config.ru:1:in `new'
  from /srv/app/current/config.ru:1:in `<main>'
  from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/rack/adapter/loader.rb:36:in `eval'
  from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/rack/adapter/loader.rb:36:in `load'
  from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/rack/adapter/loader.rb:45:in `for'
  from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/controllers/controller.rb:163:in `load_adapter'
  from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/controllers/controller.rb:67:in `start'
  from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/runner.rb:177:in `run_command'
  from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/runner.rb:143:in `run!'
  from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/bin/thin:6:in `<top (required)>'
  from /usr/local/lib/ruby/gems/1.9.1/bin/thin:19:in `load'
  from /usr/local/lib/ruby/gems/1.9.1/bin/thin:19:in `<main>'

当capistrano部署时,我在$APP_PATH / shared / bundle目录中缓存我的bundle;所以,这解释了为什么瘦抱怨没有安装宝石,因为瘦服务不会在$APP_PATH / shared / bundle中查找

这确实有效:

cd $APP_PATH/current; bundle exec thin start -d -C /etc/thin/app_x.yml

但这不是/etc/init.d/thin中瘦服务文件的工作方式.我想我可以写自己的.我只是不想解决已经解决的问题.

解决方法

我想出了这个,但我觉得它不是最好的解决方案,因为它没有利用thin的“–all”选项,它从目录中读取配置文件.相反,我修改了启动/停止/重新启动瘦服务的文件,因此对于每个应用程序,我给它一个特定的命令来启动/停止/重新启动.我确信这个命令可以改进,但现在它可以满足我的需求.

#!/bin/sh

# This is a pretty bad,but effective workaround for starting thin as a service per application.

DAEMON=/usr/local/lib/ruby/gems/1.9.1/bin/thin
# DAEMON=/usr/local/bin/bundler thin
SCRIPT_NAME=/etc/init.d/thin
CONFIG_PATH=/etc/thin

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

case "$1" in
  start)
  cd /srv/hub/current && bundle exec thin start -d -C /etc/thin/hub.yml
  ;;
  stop)
  cd /srv/hub/current && bundle exec thin stop -d -C /etc/thin/hub.yml
  ;;
  restart)
  cd /srv/hub/current && bundle exec thin restart -d -C /etc/thin/hub.yml
  ;;
  *)
  echo "Usage: $SCRIPT_NAME {start|stop|restart}" >&2
  exit 3
  ;;
esac

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读