9

私はruby1.9.2でrails3を実行し、nginx+passengerを使用してUbuntu10.04LTSマシンにデプロイしたアプリをいくつか持っています。次に、ruby 1.8.7(REE)とRails 2で実行される新しいアプリを追加する必要があります。これは、RVM、Passenger Standalone、およびリバースプロキシを使用して実現しました。

問題は、サーバーを再起動する必要があるたびに(たとえば、セキュリティ更新プログラムをインストールするために)、PassengerStandaloneを手動で起動する必要があることです。

自動的に起動する方法はありますか?MonitまたはGodを使用するように言われましたが、PassengerStandaloneで機能する適切なレシピを作成できませんでした。また、神とRVMにもいくつか問題があったので、神を使用しないソリューションがある場合、または神/ Rvmを適切に構成する方法を知っている場合は、さらに優れています。

4

4 に答える 4

15

これが私が働いたものです。Upstart(Ubuntu 10.04)を使用してパッセンジャーデーモンを起動する

私の環境はruby1.9.2とapacheを備えたrvmを使用しており、私のrailsアプリはcapistranoを介してデプロイされています

# Upstart: /etc/init/service_name.conf
description "start passenger stand-alone"
author "Me <me@myself.am>"

# Stanzas
#
# Stanzas control when and how a process is started and stopped
# See a list of stanzas here: http://upstart.ubuntu.com/wiki/Stanzas#respawn

# When to start the service
start on started mysql

# When to stop the service
stop on runlevel [016]

# 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 /var/path/to/app/staging/current
        sh HOME=/home/deploy /usr/local/rvm/gems/ruby-1.9.2-p136@appname/gems/passenger-3.0.7/bin/passenger start --user 'deploy' -p '5000' -a '127.0.0.1' -e 'production'
end script

およびapache構成:

<VirtualHost *:80>
    ServerName myapp.com

    PassengerEnabled off

                <Proxy *>
                        Order deny,allow
                        Allow from all
                </Proxy>

    ProxyPass / http://127.0.0.1:5000/
    ProxyPassReverse / http://127.0.0.1:5000/

</VirtualHost>

Upstartは、passengerが依存するENV ['HOME']を設定しないため、passengerコマンドを実行するときにそれを渡す必要があります。それ以外はかなり簡単です。

デバッグに関する注意:https>> /tmp/upstart.log 2>&1 ://serverfault.com/questions/114052/logging-a-daemons-output-with-upstart(スクリプトブロックの2行目に次のようなものを追加してください)

お役に立てれば。

于 2011-04-20T14:08:08.777 に答える
0

これを正常に開始できるシェルスクリプトを作成し、それを使用する場合はMonitまたはGodレシピで使用するか、そうでない場合はinitスクリプトで使用することをお勧めします。

サーバーが実行しているOSについては言及していませんが、最近のUbuntuの場合は、Upstartスクリプトを非常に簡単に作成できます。これは組み込みであり、Monit / Godの重要な機能を備えています。つまり、再起動してもデーモンを実行し続けることができます。

于 2011-04-19T16:44:31.327 に答える
0

私はジェムアイを使用しています-https ://github.com/kostya/eye

BUNDLE = 'bundle'
RAILS_ENV = 'production'
ROOT = File.expand_path(File.dirname(__FILE__))

Eye.config do
  logger "#{ROOT}/log/eye.log"
end

Eye.application :app do
  env 'RAILS_ENV' => RAILS_ENV
  working_dir ROOT
  trigger :flapping, :times => 10, :within => 1.minute

  process :passenger do
    daemonize true
    pid_file "tmp/pids/passenger.pid"

    start_command "#{BUNDLE} exec passenger start --port 3000 --environment #{RAILS_ENV}"
    stop_signals [:TERM, 5.seconds, :KILL]
    restart_command "kill -USR2 {PID}"

    restart_grace 10.seconds 

    check :cpu, :every => 30, :below => 80, :times => 3
    check :memory, :every => 30, :below => 70.megabytes, :times => [3,5]
  end

  process :delayed_job do
    pid_file "tmp/pids/delayed_job.pid"
    stdall "log/delayed_job.log"
    daemonize true
    stop_signals [:INT, 30.seconds, :TERM, 10.seconds, :KILL]
    restart_grace 10.seconds

    start_command "#{BUNDLE} exec rake jobs:work"
  end
end
于 2015-04-22T08:19:19.027 に答える
-1

プラットフォームによっては、ほぼ確実にinitのバリエーションが利用可能になります。Debianでは、これはinit.dです。ubuntuでは、init.dまたはupstart。RHELのようなサービスで。これらにより、起動時にサービスを管理できます。プラットフォームに適したマニュアルページを読むことをお勧めします。

于 2011-04-19T16:45:48.887 に答える