【问题标题】:Capistrano: linked file database.yml does not exist on my.server.ipadressCapistrano:链接文件 database.yml 在 my.server.ip 地址上不存在
【发布时间】:2015-03-11 08:42:23
【问题描述】:

在我尝试通过 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

我试过这个 tut https://www.gorails.com/deploy/ubuntu/14.04,这是我第一次尝试 capistrano。

【问题讨论】:

    标签: ruby-on-rails deployment ssh capistrano


    【解决方案1】:

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

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

    【讨论】:

    • 我到处寻找,试图摆脱困境。你的小费成功了。谢谢@maxd。
    • 对我来说,我有文件,但它给了我这个错误。我什至在 vim 上打开它!为什么会这样?
    【解决方案2】:

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

    这使用 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"
    

    【讨论】:

      猜你喜欢
      • 2017-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      相关资源
      最近更新 更多