2017-08-03 55 views
0

我有一个rails站点,我通过ssh使用git post-receive hook进行部署。当我进入服务器并运行bundle install时,它在2.2.2的指定ruby版本下正确运行。然而,当我推到服务器,从我的本地机器和它打“包安装命令”,我得到如下:Bundler试图在错误版本的Ruby下运行

hooks/post-receive: /usr/local/bin/bundle: /usr/bin/ruby1.9.1: bad interpreter: No such file or directory 

我找不到我的生活为什么它是指向ruby1 .9.1。该目录不存在。我在那个目录中看到了ruby2.3的目录,但没有看到正确的目录ruby2.2.2。有些东西很脏,但我无法弄清楚如何解决这个问题。任何人看到这样的事情?

UPDATE:这是我的后收到钩,按下面的请求......

#!/bin/bash 

GIT_DIR=/home/deploy/www_production 
WORK_TREE=/home/deploy/www 
export MGOTS_DATABASE_USER='user' 
export MGOTS_DATABASE_PASSWORD='pass' 

export RAILS_ENV="production" 
. ~/.bash_profile 

while read oldrev newrev ref 
do 
    if [[ $ref = refs/heads/master ]]; 
    then 
     echo "Master ref received. Deploying master branch to production..." 
     mkdir -p $WORK_TREE 
     git --work-tree=$WORK_TREE --git-dir=$GIT_DIR checkout -f 
     mkdir -p $WORK_TREE/shared/pids $WORK_TREE/shared/sockets $WORK_TREE/shared/log 

     # start deploy tasks 
     cd $WORK_TREE 
     bundle install 
     rake db:create 
     rake db:migrate 
     rake assets:precompile 
     rake requests:cleanup 
     sudo restart puma-manager 
     sudo service nginx restart 
     # end deploy tasks 
     echo "Git hooks deploy complete" 
    else 
     echo "Ref $ref successfully received. Doing nothing: only the master branch may be deployed on this server." 
    fi 
done 

UPDATE:为了清楚起见,作为答案指向正确的地方找到了答案,但没有完全说明,我在这里发布我更新的钩子文件。你可以看到这个和上面的区别,这就是解决问题的方法。请注意,可以通过键入以下命令找到rvm目录的路径:which rvm - 这就是您要指向的路径。

#!/bin/bash 

GIT_DIR=/home/deploy/www_production 
WORK_TREE=/home/deploy/www 
export MGOTS_DATABASE_USER='user' 
export MGOTS_DATABASE_PASSWORD='pass' 

export RAILS_ENV="production" 
export RUBYGEMS_GEMDEPS="/home/deploy/.rvm/[email protected]/gems" 

. ~/.bash_profile 

[[ -s "/usr/share/rvm/bin/rvm" ]] && source "/usr/share/rvm/bin/rvm" 

while read oldrev newrev ref 
do 
    if [[ $ref = refs/heads/master ]]; 
    then 
     echo "Master ref received. Deploying master branch to production..." 
     mkdir -p $WORK_TREE 
     git --work-tree=$WORK_TREE --git-dir=$GIT_DIR checkout -f 
     mkdir -p $WORK_TREE/shared/pids $WORK_TREE/shared/sockets $WORK_TREE/shared/log 

     # start deploy tasks 
     cd $WORK_TREE 
     bundle install 
     rake db:create 
     rake db:migrate 
     rake assets:precompile 
     rake requests:cleanup 
     sudo restart puma-manager 
     sudo service nginx restart 
     # end deploy tasks 
     echo "Git hooks deploy complete" 
    else 
     echo "Ref $ref successfully received. Doing nothing: only the master branch may be deployed on this server." 
    fi 
done 
+0

你的gemfile是否指定了ruby版本?如果没有把这个放在你的gemfile ruby​​中“2.2.2” –

+0

是的,我的gemfile的开头有:source'https://rubygems.org' ruby​​“2.2.2” – unclesol

+0

你的服务器已经安装了ruby 2.2.2? –

回答

2

您需要将RVM函数加载到shell脚本中。 link 或者只是切换到Rbenv :)

+0

链接答案中指示的路径不存在。我正在寻找一个“脚本”文件夹,但找不到一个。它可以被称为别的吗? – unclesol

+0

我想通过运行哪个rvm - 现在试着 – unclesol

+0

这工作!我不能奖励另外19个小时的奖励,但我会回来并奖励它。 – unclesol

0

首先,设置默认红宝石使用的版本2.2.2

您正在使用RVM?对于RVM而言:rvm use --default 2.2.2

+0

这已经完成 – unclesol

+0

你能分享你的git post-receive hook吗? – tenshiAMD

+0

是的,@tenshiAMD - 请参阅上文。我编辑了这个问题。 – unclesol

相关问题