Capistrano:my.server.ipadress 上不存在链接文件 database.yml
Capistrano: linked file database.yml does not exist on my.server.ipadress
在我尝试通过 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。
只需手动创建 /home/deploy/myrailsapp/shared/config/database.yml
文件并进行调整。
Capistrano 不会立即创建(或管理)配置文件。因此,您应该使用自己的 Capistrano
脚本、Puppet
、Chef
、Ansible
工具手动或自动执行此操作。
因为我更喜欢将我的文件集中在部署服务器上,所以我使用此任务将配置文件从配置目录部署到应用服务器上的链接文件目录。
这使用 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"
您可以使用 rake 任务上传文件。
在设置 Capistrano 后将 gem 添加到您的 Gemfile,最好在 :development 组中:
group :development do
gem 'capistrano', require: false
gem 'capistrano-rake', require: false
end
А将其添加到您的 Capfile:
require 'capistrano/rake'
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
创建文件 lib/capistrano/tasks/setup.rake
并向其中添加:
namespace :deploy do
namespace :check do
before :linked_files, :set_database_yml do
on roles(:app), in: :sequence, wait: 10 do
upload! 'config/database.yml', "#{shared_path}/config/database.yml"
end
end
end
end
在我尝试通过 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。
只需手动创建 /home/deploy/myrailsapp/shared/config/database.yml
文件并进行调整。
Capistrano 不会立即创建(或管理)配置文件。因此,您应该使用自己的 Capistrano
脚本、Puppet
、Chef
、Ansible
工具手动或自动执行此操作。
因为我更喜欢将我的文件集中在部署服务器上,所以我使用此任务将配置文件从配置目录部署到应用服务器上的链接文件目录。
这使用 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"
您可以使用 rake 任务上传文件。
在设置 Capistrano 后将 gem 添加到您的 Gemfile,最好在 :development 组中:
group :development do
gem 'capistrano', require: false
gem 'capistrano-rake', require: false
end
А将其添加到您的 Capfile:
require 'capistrano/rake'
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
创建文件 lib/capistrano/tasks/setup.rake
并向其中添加:
namespace :deploy do
namespace :check do
before :linked_files, :set_database_yml do
on roles(:app), in: :sequence, wait: 10 do
upload! 'config/database.yml', "#{shared_path}/config/database.yml"
end
end
end
end