ruby-on-rails – 在.gitignore上的configdatabase.yml上找不到部署configdatabase.yml应该使用shareddatabase.yml,怎么样?

ruby-on-rails – 在.gitignore上的configdatabase.yml上找不到部署configdatabase.yml应该使用shareddatabase.yml,怎么样?,第1张

概述我按照cap nginx unicorn上的文档进行了 *** 作,但是要了解如何正确地进行数据库部署有一些问题. > /config/database.yml不应该在git repo中(最好) >在/shared/database.yml中的生产服务器上放置database.yml >问题是在部署时它仍然会查找/config/database.yml 如何让我的deploy.rb获取/shared/da 我按照cap Nginx unicorn上的文档进行了 *** 作,但是要了解如何正确地进行数据库部署有一些问题.

> /config/database.yml不应该在git repo中(最好)
>在/shared/database.yml中的生产服务器上放置database.yml
>问题是在部署时它仍然会查找/config/database.yml

如何让我的deploy.rb获取/shared/database.yml?
搜索高和低为此无济于事:(

deploy.rb

# config/deploy.rbrequire "bundler/cAPIstrano"set :scm,:gitset :repository,"[email protected]:/srv/paintings.git"set :branch,"origin/master"set :migrate_target,:currentset :ssh_options,{:forward_agent => true}set :rails_env,"production"set :deploy_to,"/srv/paintings"set :normalize_asset_timestamps,falseset :user,"root"set :group,""set :use_sudo,truedefault_run_options[:pty] = trueset :port,5984ssh_options[:port] = 5984role :web,"109.etc"role :app,"109.etc"role :db,"109.etc",:primary => trueset(:latest_release) { fetch(:current_path) }set(:release_path) { fetch(:current_path) }set(:current_release) { fetch(:current_path) }set(:current_revision) { capture("cd #{current_path}; git rev-parse --short head").strip }set(:latest_revision) { capture("cd #{current_path}; git rev-parse --short head").strip }set(:prevIoUs_revision) { capture("cd #{current_path}; git rev-parse --short head@{1}").strip }default_environment["RAILS_ENV"] = 'production'#default_environment["PATH"]         = "/bin/bash"#default_environment["GEM_HOME"]     = "/usr/local/rvm/gems/ruby-1.9.3-p125"#default_environment["GEM_PATH"]     = "/usr/local/rvm/gems/ruby-1.9.3-p125"#default_environment["RUBY_VERSION"] = "ruby 1.9.3p125"#default_run_options[:shell] = 'bash'namespace :deploy do  desc "Deploy your application"  task :default do    update    restart  end  desc "Setup your git-based deployment app"  task :setup,:except => {:no_release => true} do    dirs = [deploy_to,shared_path]    dirs += shared_children.map { |d| file.join(shared_path,d) }    run "#{try_sudo} mkdir -p #{dirs.join(' ')} && #{try_sudo} chmod g+w #{dirs.join(' ')}"    run "git clone #{repository} #{current_path}"  end  task :cold do    update    migrate  end  task :update do    transaction do      update_code    end  end  desc "Update the deployed code."  task :update_code,:except => {:no_release => true} do    run "cd #{current_path}; git fetch origin; git reset --hard #{branch}"    finalize_update  end  desc "Update the database (overwritten to avoID symlink)"  task :migrations do    transaction do      update_code    end    migrate    restart  end  task :finalize_update,:except => {:no_release => true} do    run "chmod -R g+w #{latest_release}" if fetch(:group_writable,true)    # mkdir -p is making sure that the directorIEs are there for some SCM's that don't    # save empty folders    run <<-CMD      rm -rf #{latest_release}/log #{latest_release}/public/system #{latest_release}/tmp/pIDs &&      mkdir -p #{latest_release}/public &&      mkdir -p #{latest_release}/tmp &&      ln -s #{shared_path}/log #{latest_release}/log &&      ln -s #{shared_path}/system #{latest_release}/public/system &&      ln -s #{shared_path}/pIDs #{latest_release}/tmp/pIDs    CMD    if fetch(:normalize_asset_timestamps,true)      stamp = Time.Now.utc.strftime("%Y%m%d%H%M.%s")      asset_paths = fetch(:public_children,%w(images stylesheets JavaScripts)).map { |p| "#{latest_release}/public/#{p}" }.join(" ")      run "find #{asset_paths} -exec touch -t #{stamp} {} ';'; true",:env => {"TZ" => "UTC"}    end  end  desc "Zero-downtime restart of Unicorn"  task :restart,:except => {:no_release => true} do    #run "kill -s USR2 'cat /srv/paintings/shared/pIDs/unicorn.pID'"    run "kill -s USR2 'cat /srv/paintings/shared/tmp/unicorn.pID'"  end  desc "Start unicorn"  task :start,:except => {:no_release => true} do    run "cd #{current_path} ; bundle exec unicorn_rails -c config/unicorn.rb -D"  end  desc "Stop unicorn"  task :stop,:except => {:no_release => true} do    #run "kill -s QUIT 'cat /srv/paintings/shared/pIDs/unicorn.pID'"    run "kill -s QUIT 'cat /tmp/unicorn.pID'"  end  namespace :rollback do    desc "Moves the repo back to the prevIoUs version of head"    task :repo,:except => {:no_release => true} do      set :branch,"head@{1}"      deploy.default    end    desc "Rewrite reflog so head@{1} will continue to point to at the next prevIoUs release."    task :cleanup,:except => {:no_release => true} do      run "cd #{current_path}; git reflog delete --rewrite head@{1}; git reflog delete --rewrite head@{1}"    end    desc "Rolls back to the prevIoUsly deployed version."    task :default do      rollback.repo      rollback.cleanup    end  endenddef run_rake(cmd)  run "cd #{current_path}; #{rake} #{cmd}"end
解决方法 我使用的是非常相似的deploy.rb,但我在finalize_update方法中还有一个符号链接:

ln -sf #{shared_path}/database.yml #{latest_release}/config/database.yml
总结

以上是内存溢出为你收集整理的ruby-on-rails – 在.gitignore上的/config/database.yml上找不到部署/config/database.yml应该使用/shared/database.yml,怎么样?全部内容,希望文章能够帮你解决ruby-on-rails – 在.gitignore上的/config/database.yml上找不到部署/config/database.yml应该使用/shared/database.yml,怎么样?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1293472.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-10
下一篇 2022-06-10

发表评论

登录后才能评论

评论列表(0条)

保存