0

我想承載我的第一個rails應用程序,但我有以下錯誤。錯誤運行帽部署:冷

servers: ["208.68.37.172"] 
    [208.68.37.172] executing command 
    command finished in 1098ms 
    triggering after callbacks for `deploy:update_code' 
    * executing `deploy:assets:precompile' 
    * executing "cd /home/deployer/apps/cf/current && env RBENV_VERSION=\"1.9.3-p194\" /home/deployer/.rbenv/bin/rbenv exec bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile --trace" 
    servers: ["208.68.37.172"] 
    [208.68.37.172] executing command 
** [out :: 208.68.37.172] sh: 1: cd: 
** [out :: 208.68.37.172] can't cd to /home/deployer/apps/cf/current 
** [out :: 208.68.37.172] 
    command finished in 1660ms 
*** [deploy:update_code] rolling back 
    * executing "rm -rf /home/deployer/apps/cf/releases/20121117131510; true" 
    servers: ["208.68.37.172"] 
    [208.68.37.172] executing command 
    command finished in 2548ms 
failed: "sh -c 'cd /home/deployer/apps/cf/current && env RBENV_VERSION=\"1.9.3-p194\" /home/deployer/.rbenv/bin/rbenv exec bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile --trace'" on 208.68.37.172 

我deploy.rb低於

require 'capistrano-rbenv' 
require "bundler/capistrano" 


server "208.68.37.172", :web, :app, :db, primary: true 

set :application, "cf" 
set :user, "deployer" 
set :deploy_to, "/home/#{user}/apps/#{application}" 
set :deploy_via, :remote_cache 
set :use_sudo, false 



set :scm, "git" 
set :repository, "[email protected]:ramza1/#{application}.git" 
set :branch, "master" 

default_run_options[:pty] = true 
ssh_options[:forward_agent] = true 

after "deploy", "deploy:cleanup" # keep only the last 5 releases 

namespace :deploy do 
    %w[start stop restart].each do |command| 
    desc "#{command} unicorn server" 
    task command, roles: :app, except: {no_release: true} do 
     run "/etc/init.d/unicorn_#{application} #{command}" 
    end 
    end 

    namespace :assets do 
    task :precompile, :roles => :web, :except => { :no_release => true } do 
     run "cd #{current_path} && #{rake} RAILS_ENV=#{rails_env} RAILS_GROUPS=assets assets:precompile --trace" 
    end 
    end 

    task :setup_config, roles: :app do 
    sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}" 
    sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}" 
    run "mkdir -p #{shared_path}/config" 
    put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml" 
    puts "Now edit the config files in #{shared_path}." 
    end 
    after "deploy:setup", "deploy:setup_config" 

    task :symlink_config, roles: :app do 
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml" 
    end 
    after "deploy:finalize_update", "deploy:symlink_config" 

    desc "Make sure local git is in sync with remote." 
    task :check_revision, roles: :web do 
    unless `git rev-parse HEAD` == `git rev-parse origin/master` 
     puts "WARNING: HEAD is not the same as origin/master" 
     puts "Run `git push` to sync changes." 
     exit 
    end 
    end 
    before "deploy", "deploy:check_revision" 


end 

我unicorn.rb低於

root = "/home/deployer/apps/cf/current" 
working_directory root 
pid "#{root}/tmp/pids/unicorn.pid" 
stderr_path "#{root}/log/unicorn.log" 
stdout_path "#{root}/log/unicorn.log" 

listen "/tmp/unicorn.blog.sock" 
worker_processes 2 
timeout 30 

nginx.conf

upstream unicorn { 
    server unix:/tmp/unicorn.cf.sock fail_timeout=0; 
} 

server { 
    listen 80 default deferred; 
    server_name completefashiononline.com; 
    root /home/deployer/apps/cf/current/public; 

    location ^~ /assets/ { 
    gzip_static on; 
    expires max; 
    add_header Cache-Control public; 
    } 

    try_files $uri/index.html $uri @unicorn; 
    location @unicorn { 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host $http_host; 
    proxy_redirect off; 
    proxy_pass http://unicorn; 
    } 

    error_page 500 502 503 504 /500.html; 
    client_max_body_size 4G; 
    keepalive_timeout 10; 
} 

unicorn_init.sh

#!/bin/sh 
### BEGIN INIT INFO 
# Provides:   unicorn 
# Required-Start: $remote_fs $syslog 
# Required-Stop:  $remote_fs $syslog 
# Default-Start:  2 3 4 5 
# Default-Stop:  0 1 6 
# Short-Description: Manage unicorn server 
# Description:  Start, stop, restart unicorn server for a specific application. 
### END INIT INFO 
set -e 

# Feel free to change any of the following variables for your app: 
TIMEOUT=${TIMEOUT-60} 
APP_ROOT=/home/deployer/apps/cf/current 
PID=$APP_ROOT/tmp/pids/unicorn.pid 
CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production" 
AS_USER=deployer 
set -u 

OLD_PIN="$PID.oldbin" 

sig() { 
    test -s "$PID" && kill -$1 `cat $PID` 
} 

oldsig() { 
    test -s $OLD_PIN && kill -$1 `cat $OLD_PIN` 
} 

run() { 
    if [ "$(id -un)" = "$AS_USER" ]; then 
    eval $1 
    else 
    su -c "$1" - $AS_USER 
    fi 
} 

case "$1" in 
start) 
    sig 0 && echo >&2 "Already running" && exit 0 
    run "$CMD" 
    ;; 
stop) 
    sig QUIT && exit 0 
    echo >&2 "Not running" 
    ;; 
force-stop) 
    sig TERM && exit 0 
    echo >&2 "Not running" 
    ;; 
restart|reload) 
    sig HUP && echo reloaded OK && exit 0 
    echo >&2 "Couldn't reload, starting '$CMD' instead" 
    run "$CMD" 
    ;; 
upgrade) 
    if sig USR2 && sleep 2 && sig 0 && oldsig QUIT 
    then 
    n=$TIMEOUT 
    while test -s $OLD_PIN && test $n -ge 0 
    do 
     printf '.' && sleep 1 && n=$(($n - 1)) 
    done 
    echo 

    if test $n -lt 0 && test -s $OLD_PIN 
    then 
     echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds" 
     exit 1 
    fi 
    exit 0 
    fi 
    echo >&2 "Couldn't upgrade, starting '$CMD' instead" 
    run "$CMD" 
    ;; 
reopen-logs) 
    sig USR1 
    ;; 
*) 
    echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>" 
    exit 1 
    ;; 
esac 

這是我所用過的。請任何幫助解決這個問題將是偉大的。謝謝

+0

似乎有某事錯誤的預編譯任務。您能否使用部署中的相同用戶運行服務器上的最後一條命令?也許這給你一個更好的輸出 – 23tux

回答

1

基本上,你運行的資源預編譯任務在deploy:update_code之後運行。此時base_path內沒有「當前」目錄。這就是爲什麼你會得到這個錯誤。

您應該對其進行更改,以便資源:預編譯任務在部署後運行:finalize_update或更好,然後使用內置資產預編譯。

你可以通過添加這對您的Capfile:

load 'deploy/assets' 
+0

嗨,我也遇到了這個問題。然而'load'deploy/assets''已經被添加到我的Capfile中。有什麼我應該檢查的嗎? –

+0

@GaryLai嗨,你是否得到完全相同的錯誤?如果沒有,請讓我知道,我會盡力幫助。如果你得到完全相同的錯誤,你使用的是什麼版本的帽子? –