Ruby on rails Bash脚本没有';启动时不能运行
我编写了一个bash脚本来启动两个项目的瘦服务器Ruby on rails Bash脚本没有';启动时不能运行,ruby-on-rails,boot,restart,thin,Ruby On Rails,Boot,Restart,Thin,我编写了一个bash脚本来启动两个项目的瘦服务器 #! /bin/sh cd /path/to/my/project_1 thin -e production -p 3000 --daemonize -s 10 start 然后将其放置在/etc/init.d/start\u thin中。给了它755个权限。跑步: sudo update-rc.d start_thin defaults. 然后 “精简”未启动。谢谢 更新: 经过长时间的斗争,我发现这个错误只有在thin以/etc/ini
#! /bin/sh
cd /path/to/my/project_1
thin -e production -p 3000 --daemonize -s 10 start
然后将其放置在/etc/init.d/start\u thin中。给了它755个权限。跑步:
sudo update-rc.d start_thin defaults.
然后
“精简”未启动。谢谢
更新:
经过长时间的斗争,我发现这个错误只有在thin以/etc/init.d/thin启动时才会发生:
将PID写入tmp/pids/thin.3000.PID
使用rails适配器/path/.rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.11/lib/mysql2/mysql2.so:
[BUG]分段错误ruby 1.8.7(2010-08-16补丁级别302)
[i686 linux]
我想现在唯一合乎逻辑的事情是切换到“正常”的SQLGEM
更新2:
我找到了以前帮过我的,但现在帮不了我了
更新3:
我使用重新安装的RVM。现在,当启动脚本运行时,我在日志中看到缺少一个gem:multi_json-1.1.0。我安装了它并把它放进了文件。没有帮助。不过,当我手动执行bash脚本时——没有问题。只有在启动时,它才会抱怨multi_json-1.1.0
更新4:
仅在启动时,thin的日志文件包含:
当我安装了ruby 1.9.2时,我不明白为什么它会使用1.8 gems:-
>> Writing PID to tmp/pids/thin.3000.pid
>> Using rails adapter
>> Exiting!
/usr/lib/ruby/gems/1.8/gems/bundler-1.0.15/lib/bundler/spec_set.rb:87:in `materialize': Could not find multi_json-1.1.0 in any of the sources (Bundler::GemNotFound)
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.15/lib/bundler/spec_set.rb:81:in `map!'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.15/lib/bundler/spec_set.rb:81:in `materialize'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.15/lib/bundler/definition.rb:90:in `specs'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.15/lib/bundler/definition.rb:135:in `specs_for'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.15/lib/bundler/definition.rb:124:in `requested_specs'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.15/lib/bundler/environment.rb:23:in `requested_specs'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.15/lib/bundler/runtime.rb:11:in `setup'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.15/lib/bundler.rb:107:in `setup'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.15/lib/bundler/setup.rb:17
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from /home/user1/myproj1/config/boot.rb:6
from /home/user1/myproj1/config/application.rb:1:in `require'
from /home/user1/myproj1/config/application.rb:1
from /home/user1/myproj1/config/environment.rb:2:in `require'
from /home/user1/myproj1/config/environment.rb:2
from /usr/lib/ruby/1.8/rack/adapter/rails.rb:42:in `require'
from /usr/lib/ruby/1.8/rack/adapter/rails.rb:42:in `load_application'
from /usr/lib/ruby/1.8/rack/adapter/rails.rb:23:in `initialize'
from /usr/lib/ruby/1.8/rack/adapter/loader.rb:36:in `new'
from /usr/lib/ruby/1.8/rack/adapter/loader.rb:36:in `for'
from /usr/lib/ruby/1.8/thin/controllers/controller.rb:163:in `load_adapter'
from /usr/lib/ruby/1.8/thin/controllers/controller.rb:67:in `start'
from /usr/lib/ruby/1.8/thin/runner.rb:174:in `send'
from /usr/lib/ruby/1.8/thin/runner.rb:174:in `run_command'
from /usr/lib/ruby/1.8/thin/runner.rb:140:in `run!'
from /usr/bin/thin:6
所以,很自然地,我安装了multi_json gem,然后,捆绑安装,然后,你觉得呢?同样的老问题:)。尝试
sudo chmod u+x/etc/init.d/start\u thin
从外观上看,thin的启动方式相当混乱,使用ruby 1.8.7解释器,但使用为1.9.2编译的gems,这听起来是个非常糟糕的主意。这听起来好像rvm设置不正确
首先尝试加载rvm。如果在全球范围内安装了rvm,则可以使用
source /etc/profile.d/rvm.sh
如果没有,请更改该路径以反映运行此脚本的用户的rvm安装位置
此外,rvm需要bash,因此请确保您的shebang是/bin/bash
而不是/bin/sh
(有时sh
只是bash
的符号链接,但您不应该依赖它)我找到了答案
在我的bash脚本的开头添加了以下行:
# 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.2
为了检查所有内容是否正确,请在bash内部和我使用的上述代码的正下方
type rvm | head -1
如果上面的输出:rvm是一个函数,那么一切都很好
注意:如果由于某种原因,cron文件似乎不能与RVM一起工作,那么应该对其执行相同的操作 如果它位于该目录中,请尝试
/thin
。很可能它不在路径中。谢谢,我尝试了,并再次尝试给出完整的路径。不走运。一个问题是cd在子shell中运行。但问题在于如何启动精简版。我检查了日志,一切看起来都很好。所以这一定是另一个问题。目前,我正在使用thin-c/path/to/my/project\u 1-e production-p3000--daemonize-s10 start您可以尝试sudo start\u thin
或sudo restart\u thin
。您不需要重新启动来测试脚本(这不是windows)。在这种情况下,当您执行脚本时,会生成一个新的shell。在这个新shell中,执行cd
命令,然后执行thin
命令。另一个问题与此无关,它已经拥有755个权限。它在启动时运行,我也可以用(.)点启动来运行它。我可以看到它输出“在端口上开始精简…”消息。但是,要么是启动时有什么东西杀死了它,我怀疑是环境出了问题。谢谢!我照你说的做了,还是不行。我还读到RVM有很多bug,可能Ruby的早期版本应该工作得更好。我正在考虑从一开始就重新安装它。
type rvm | head -1