Capistrano:my.server.ip地址上不存在链接文件database.yml

时间:2015-03-11 08:42:24

标签: ruby-on-rails deployment ssh capistrano

在我尝试通过capistrano将我的应用部署到我的服务器后,我收到此错误消息:

DEBUG [605f198a] Finished in 0.084 seconds with exit status 1 (failed).
ERROR linked file /home/deploy/myrailsapp/shared/config/database.yml does not exist on xx.xxx.xx.xxx
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy@xx.xxx.xx.xxx: exit

SystemExit: exit

Tasks: TOP => deploy:check:linked_files
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as deploy@xx.xxx.xx.xxx: exit

我的deploy.rb是:

set :deploy_to, '/home/deploy/myrailsapp'
set :linked_files, %w{config/database.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}



namespace :deploy do
  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      execute :touch, release_path.join('tmp/restart.txt')
    end
  end
  after :publishing, 'deploy:restart'
  after :finishing, 'deploy:cleanup'
end


namespace :deploy do
  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
      # Here we can do anything such as:
      # within release_path do
      #   execute :rake, 'cache:clear'
      # end
    end
  end
end

我尝试了这个啧啧https://www.gorails.com/deploy/ubuntu/14.04,这是我第一次尝试使用capistrano。

2 个答案:

答案 0 :(得分:31)

手动创建/home/deploy/myrailsapp/shared/config/database.yml文件并进行调整。

Capistrano不会立即创建(或管理)配置文件。因此,您应该手动执行或自动使用自己的Capistrano脚本,PuppetChefAnsible工具。

答案 1 :(得分:5)

由于我更喜欢​​将我的文件放在部署服务器上,我使用此任务将配置文件中的配置文件部署到应用服务器上的链接文件目录。

这使用rsync,因为我使用capistrano-rsync来部署。

namespace :deploy do

  task :copy_config do
    on release_roles :app do |role|
      fetch(:linked_files).each do |linked_file|
        user = role.user + "@" if role.user
        hostname = role.hostname
        linked_files(shared_path).each do |file|
          run_locally do
            execute :rsync, "config/#{file.to_s.gsub(/.*\/(.*)$/,"\\1")}", "#{user}#{hostname}:#{file.to_s.gsub(/(.*)\/[^\/]*$/, "\\1")}/"
          end
        end
      end
    end
  end

end
before "deploy:check:linked_files", "deploy:copy_config"