2017-08-03 29 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

相關問題