Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mina 启动unicorn时报错 #36

Closed
shuiiiiiimu opened this issue Apr 11, 2015 · 9 comments
Closed

mina 启动unicorn时报错 #36

shuiiiiiimu opened this issue Apr 11, 2015 · 9 comments
Labels

Comments

@shuiiiiiimu
Copy link

在尝试使用新的mina部署框架。

wblog项目在服务器上首次部署,遇到一些问题。
一直部署下来,遇到的不少问题都是google解决掉了。

其中最坑的就是

-----> Installing gem dependencies using Bundler
$ mkdir -p "/home/deploy/web/wblog/shared/bundle"
$ mkdir -p "./vendor"
$ ln -s "/home/deploy/web/wblog/shared/bundle" "./vendor/bundle"
$ bundle install --without development:test --path "./vendor/bundle" --deployment

经常报错,然后终止。有好几个gem,都要手动去gem install xxx -v 'xxx'这样子。再执行mina deploy -v

现在unicorn启动报错,异常信息如下:

-----> Start Unicorn
$ 
      cd /home/deploy/web/wblog/current && bundle exec unicorn -c config/unicorn/production.rb -E production -D

/home/deploy/web/wblog/releases/1/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/configurator.rb:75:in `read': No such file or directory @ rb_sysopen - config/unicorn/production.rb (Errno::ENOENT)
    from /home/deploy/web/wblog/releases/1/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/configurator.rb:75:in `reload'
    from /home/deploy/web/wblog/releases/1/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/configurator.rb:68:in `initialize'
    from /home/deploy/web/wblog/releases/1/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:100:in `new'
    from /home/deploy/web/wblog/releases/1/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:100:in `initialize'
    from /home/deploy/web/wblog/releases/1/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/bin/unicorn:126:in `new'
    from /home/deploy/web/wblog/releases/1/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/bin/unicorn:126:in `<top (required)>'
    from /home/deploy/web/wblog/releases/1/vendor/bundle/ruby/2.1.0/bin/unicorn:23:in `load'
    from /home/deploy/web/wblog/releases/1/vendor/bundle/ruby/2.1.0/bin/unicorn:23:in `<main>'
master failed to start, check stderr log for details
! ERROR: Deploy failed.

发现这跟你在deploy.rb中做的配置有关。

应该怎么解决呢?

@windy
Copy link
Owner

windy commented Apr 11, 2015

@Zhangsm 你列一下 /home/deploy/web/wblog/current 下面是否有文件? 估计还没有链接成功.

@windy windy added the question label Apr 11, 2015
@windy
Copy link
Owner

windy commented Apr 11, 2015

@Zhangsm 我这两天更新了 deploy.rb 脚本, 依赖更少了, 还支持了英文博客. 你可以看下.

@shuiiiiiimu
Copy link
Author

@windy 按照部署流程,bundle install自后就是建立软链接,再就是Unicorn之类的操作。但mina部署失败之后,他会马上回滚上一步操作,也就是unicorn启动失败后就会删除软链接。

我建立ruby用户,重新部署下看看。

@windy
Copy link
Owner

windy commented Apr 11, 2015

@Zhangsm 嗯, 你如果有需要可以加我 skype, 我可以及时回复你.

@windy
Copy link
Owner

windy commented Apr 11, 2015

@Zhangsm 我 skype 是 lyfi2003

@shuiiiiiimu
Copy link
Author

嗯嗯,为了帮助更多的人。我还是把部署中遇到的一些小问题在这里说明吧!!哈哈。。。

首先,非常感谢 @windy 开源这个项目。我列下我遇到的问题吧,不要见怪。。。

1.就是deploy.rb中:

task :environment do
  # queue! %[source /usr/local/rvm/scripts/rvm]
 ###其实很多人测试环境不一样,这里要注意改动###
  queue! %[source /home/#{user}/.rvm/scripts/rvm]
  queue! %[rvm use 2.1.2]
end

2.首次部署的时候,bundle install 都会从https://rubygems.orgfetch gem,总会莫名其妙的报些SSL connection rest这样的错误。。。然后mina task终止。。。然后再重新mina deploy -v有时候有可以。。。反正bundle install 就是没那么轻松。。。哈哈。。。

-----> Installing gem dependencies using Bundler
$ mkdir -p "/home/ruby/wblog/shared/bundle"
$ mkdir -p "./vendor"
$ ln -s "/home/ruby/wblog/shared/bundle" "./vendor/bundle"
$ bundle install --without development:test --path "./vendor/bundle" --deployment
Using rake 10.4.2
Using i18n 0.7.0

3.到启动unicorn的时候,也会报错:

-----> Starting Unicorn...
/home/ruby/wblog/releases/1 not found
-----> Done. Deployed v1

于是,我修改下mina-unicorngem包源码,打印该语句出来看看

-----> Starting Unicorn...
/home/ruby/wblog/current
BUNDLE_GEMFILE= RAILS_ENV=production bundle exec unicorn -c /home/ruby/wblog/current/config/unicorn/zh.rb -E production -D
/home/ruby/wblog/releases/2 not found
-----> Done. Deployed v2

发现BUNDLE_GEMFILE读取不到,为空。在unicorn相关配置中找到

before_exec do |server|
  ENV["BUNDLE_GEMFILE"] = "#{app_path}/Gemfile"
end

不知道神马原因为空,改成set :bundle_gemfile = "#{app_path}/Gemfile"会不会好点呢?于是我人肉启动:

BUNDLE_GEMFILE=/home/ruby/wblog/current/Gemfile RAILS_ENV=production bundle exec unicorn -c /home/ruby/wblog/current/config/unicorn/zh.rb -E production -D

启动成功了。于是就产生了/tmp/unicorn_wblog_zh.sock这个文件。
到这一步,接着配置nginx,应该就没有什么问题了吧。

这是一个优秀的项目,值得去学习!只不过我遇到的问题多了一点。。。。

@windy
Copy link
Owner

windy commented Apr 11, 2015

@Zhangsm bundle 的问题不能怪别人哈, 谁让我们国内的网络封了 rubygems.org 呢...
但也有其他方法, 比如 wblog Gemfile 里其实添加了 RUBY_TAOBAO 的环境变量, 如果你的环境在国内, 就修改一下 deploy.rb

task :environment do
export RUBY_TAOBAO=1

....

end

这样就会用 taobao 的源来 bundle.

unicorn 的问题, 你也可以用 mina uniorn:restart -S 来查看脚本内容.

mina 是个好东西, 第一次布署遇到类似问题很正常, 以后就方便多了.

@shuiiiiiimu
Copy link
Author

如果在deploy.rb中加入这个set :term_mode, nil就更加妥妥的了。哈哈。。。。

@windy
Copy link
Owner

windy commented Apr 12, 2015

@Zhangsm 这个要看你用的啥终端:) mac 下默认的显示效果非常好.

我把这个 issue 先关了, 为了方便其他人找到这里, 我把链接加到 wiki 里了, 也谢谢你的布署分享 👍

@windy windy closed this as completed Apr 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants