新手问题 第二个项目部署上之后怎么重启 passenger?

chairy11 · 2015年01月04日 · 最后由 chairy11 回复于 2015年01月05日 · 6134 次阅读

问题描述

同一个主机,之前已经有另一个项目在跑。 现在新增一个项目,监听另一个端口。 在 niginx 里面设置我是这么写的:

 server {
        listen       8888;
        server_name  xxx.xxx.xxx.xxx;
        passenger_enabled on;
        charset utf-8;
        root /var/www/a_project/current/public;
        rails_env production;
}

 server {
        listen       9999;
        server_name  xxx.xxx.xxx.xxx;
        charset utf-8;
        root /var/www/b_project/current/public;
        passenger_enabled on;
        rails_env production;
      }

现在查看 niginx 是正常监听的, 重启 niginx 之后,niginx 是正常监听的

Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 0.0.0.0:9999                0.0.0.0:*                   LISTEN 

但我不知道怎么才能重启 passenger

cd /var/www/b_project
touch tmp/restart.txt

会提示:touch: 无法创建"tmp/restart.txt": 没有那个文件或目录

cd /var/www/b_project mkdir -p tmp touch tmp/restart.txt

touch tmp/restart.txt 是重启当前项目。

Phusion Passenger checks whether the timestamp of this file has changed in order to determine whether the application should be restarted.

https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.html 重启 nginx 用nginx -s reload

#1 楼 @taomaree #2 楼 @flowerwrong 难道意思是,我自己创建一个 tmp/restart.txt就行?这个txt里面什么都不写? (a_project 的时候好像是自动生成的吧,我没创建过,但我一直用touch tmp/restart.txt重启。

#2 楼 @flowerwrong 我是刚把 b_project 弄上去,已经重启了 nginx,但没正常打开,说 something wrong, 所以我觉得应该是没有弄 passenger……

#3 楼 @chairy11 timestamp of this file has changed 不用写任何东西,passenger 会监听该文件的时间戳,如果改变就会自动重启项目。

#4 楼 @chairy11 something went wrong 是 500,你项目的问题,查看你的项目下面的log/production.log

我记得 nginx.conf 这样的配置可以配置很多个吧,指定对应的 conf 重启就可以了吧。。。记不得了,隐约有印象可以这样做

#5 楼 @flowerwrong 我看 log 只显示了我创建数据库的行为,没有记录登录相关的行为……难道是我的 nginx 设置不对?

#5 楼 @flowerwrong 看蒙我了 …… 我看了看 nginx 的 error 日志,怀疑是不是因为我上个项目用的是 ruby-2.1.2,这个项目用的是 ruby-2.2.0, (而且我连 rvm 都升级了),然后之前的 passenger 装在 rvm/gems/ruby-2.1.2/gems 里,所以它找不到要用的 passenger……

要不我再装个 passenger 看看……

[ 2015-01-05 02:56:09.7061 29783/7f54445d6700 Pool2/Implementation.cpp:287 ]: Could not spawn process for application /var/www/b_project/current: An error occured while starting up the preloader.
  Error ID: 9ad6e2b0
  Error details saved to: /tmp/passenger-error-3qukEK.html
  Message from application: <p>It looks like Bundler could not find a gem. Maybe you didn't install all the gems that this application needs. To install your gems, please run:</p>

  <pre class="commands">bundle install</pre>

<p>If that didn't work, then maybe the problem is that your gems are installed to <code>//.rvm/gems</code>, while at the same time you set <code>PassengerRuby</code> (Apache) or <code>passenger_ruby</code> (Nginx) to <code>/usr/local/rvm/gems/ruby-2.1.2/wrappers/ruby</code>. Because of the latter, RVM does not load gems from the home directory.</p>

<p>To make RVM load gems from the home directory, you need to set <code>PassengerRuby</code>/<code>passenger_ruby</code> to an RVM wrapper script inside the home directory:</p>

<ol>
  <li>Login as nobody.</li>
  <li>Enable RVM mixed mode by running:
      <pre class="commands">rvm user gemsets</pre></li>
  <li>Run this to find out what to set <code>PassengerRuby</code>/<code>passenger_ruby</code> to:
      <pre class="commands">/usr/local/rvm/gems/ruby-2.1.2/wrappers/ruby \
/usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.53/bin/passenger-config --detect-ruby</pre></li>
</ol>

<p>If that didn't help either, then maybe your application is being run under a different environment than it's supposed to. Please check the following:</p>

<ol>
  <li>Is this app supposed to be run as the <code>nobody</code> user?</li>
  <li>Is this app being run on the correct Ruby interpreter? Below you will
      see which Ruby interpreter Phusion Passenger attempted to use.</li>
  <li>Please check whether the correct RVM gemset is being used.</li>
  <li>Sometimes, RVM gemsets may be broken.
      <a href="https://github.com/phusion/passenger/wiki/Resetting-RVM-gemsets">Try resetting them.</a></li>
</ol>

<p>-------- The exception is as follows: -------</p>
Could not find rake-10.4.2 in any of the sources (Bundler::GemNotFound)
<pre>  /usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/spec_set.rb:92:in `block in materialize&#39;
  /usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/spec_set.rb:85:in `map!&#39;
  /usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/spec_set.rb:85:in `materialize&#39;
  /usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/definition.rb:132:in `specs&#39;
  /usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/definition.rb:177:in `specs_for&#39;
  /usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/definition.rb:166:in `requested_specs&#39;
  /usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/environment.rb:18:in `requested_specs&#39;
  /usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/runtime.rb:13:in `setup&#39;
  /usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler.rb:121:in `setup&#39;
  /usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/setup.rb:17:in `&lt;top (required)&gt;&#39;
  /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:in `require&#39;
  /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require&#39;
  /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:144:in `require&#39;
  /usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.53/lib/phusion_passenger/loader_shared_helpers.rb:263:in `block in run_load_path_setup_code&#39;
  /usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.53/lib/phusion_passenger/loader_shared_helpers.rb:366:in `running_bundler&#39;
  /usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.53/lib/phusion_passenger/loader_shared_helpers.rb:261:in `run_load_path_setup_code&#39;
  /usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.53/helper-scripts/rack-preloader.rb:100:in `preload_app&#39;
  /usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.53/helper-scripts/rack-preloader.rb:158:in `&lt;module:App&gt;&#39;
  /usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.53/helper-scripts/rack-preloader.rb:29:in `&lt;module:PhusionPassenger&gt;&#39;
  /usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.53/helper-scripts/rack-preloader.rb:28:in `&lt;main&gt;&#39;</pre>


[ 2015-01-05 02:56:09.7123 29783/7f54421a7700 agents/HelperAgent/RequestHandler.h:2306 ]: [Client 41] Cannot checkout session because a spawning error occurred. The identifier of the error is 9ad6e2b0. Please see earlier logs for details about the error.

#5 楼 @flowerwrong 额,装完了新 passenger,还是没解决。

#9 楼 @chairy11 我不知道了耶, 有说先bundle install , 如果不行,可能是你的 passengerDefaultRuby 路径有点问题 我的 rvm 是装在用户目录的,用的是rvm default use版本 PassengerDefaultRuby /home/my_name/.rvm/wrappers/default/ruby 这个配置可以写在单个 vhost 文件里面的,用于指定单个项目的 ruby 版本。

在 nginx 的 server 配置使用 passenger_ruby 指定当前 server 对应的 app 使用的 ruby 版本。 Ref: https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html#PassengerRuby

#11 楼 @appell 下午设置过 passenger_root, passenger_ruby,还是不行,貌似已经安装的 passenger 有它能对应的 ruby 版本? 现在感觉问题好像又出在 gemset 上了,明天再接着折腾……哎呀呀,莫名其妙啊……

#11 楼 @appell 哦,原来可以对应不同版本,我明天再试试。今天折腾崩溃了。谢谢哦:)

需要 登录 后方可回复, 如果你还没有账号请 注册新账号