4

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

シンサービスが開始されると、以下が実行されます

シンスタート --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 ディレクトリにキャッシュされます。したがって、これは、シンサービスが $APP_PATH/shared/bundle を調べないため、インストールされていない宝石についてシンが不平を言う理由を説明しています

これは機能します:

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

しかし、それは /etc/init.d/thin のシン サービス ファイルが機能する方法ではありません。私は自分で書くことができたと思います。すでに解決済みの問題を解決したくないだけです。

4

1 に答える 1

1

私はこれを思いついたが、ディレクトリから設定ファイルを読み取る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
于 2010-11-24T17:40:24.770 に答える