我正在尝试让capistrano将我的rails应用程序部署到vps。
我登录了vps,添加了一个新的'deployer'用户并通过以下方式给了他sudo权限:
adduser deployer
和visudo
deployer ALL=(ALL:ALL) ALL
我安装了rvm,ruby,postgres,postfix和nginx。全部使用apt-get,最新版本的ruby和rvm。在我正在使用的gem文件中:
gem 'unicorn'
# Deploy with Capistrano
gem 'capistrano'
gem 'rvm-capistrano', '>= 1.3.0.rc11'
尝试运行cap deploy:setup,我遇到了一堆rvm错误,但通过在cap deploy上重新安装rvm来修复它们:根据capistrano github自述文件,在deploy.rb文件中使用以下命令进行设置:
set :rvm_ruby_string, 'ruby-1.9.3-p392' # use the same ruby as used locally for deployment
set :rvm_install_ruby_params, '--1.9' # for jruby/rbx default to 1.9 mode
set :rvm_install_pkgs, %w[libyaml openssl] # package list from https://rvm.io/packages
set :rvm_install_ruby_params, '--with-opt-dir=/usr/local/rvm/usr' # package support
before 'deploy:setup', 'rvm:install_rvm' # install RVM
before 'deploy:setup', 'rvm:install_pkgs' # install RVM packages before Ruby
before 'deploy:setup', 'rvm:install_ruby' # install Ruby and create gemset, or:
before 'deploy:setup', 'rvm:create_gemset' # only create gemset
before 'deploy:setup', 'rvm:import_gemset' # import gemset from file
当我运行cap deploy:cold时,它会很好,直到它给出错误的结尾:
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell 'ruby-1.9.3-p392' -c 'cd /home/deployer/apps/blog/releases/20130301223924 && bundle install --gemfile /home/deployer/apps/blog/releases/20130301223924/Gemfile --path /home/deployer/apps/blog/shared/bundle --deployment --quiet --without development test'" on 198.211.127.46
所以我使用:
将我的'deployer'用户添加到'rvm'组中sudo usermod -G rvm deployer
运行上限部署后:冷,得到错误:
** [out :: 198.211.127.46] cannot create directory `/home/deployer/apps/blog/releases/20130301223718'
** [out :: 198.211.127.46] : Permission denied
非常感谢任何见解。我快到了。
这是我的deploy.rb文件:
require "bundler/capistrano"
require "rvm/capistrano"
server "198.211.127.46", :web, :app, :db, primary: true
set :port, 46000
set :application, "blog"
set :user, "deployer"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, true
set :keep_releases, 5
set :scm, "git"
set :repository, "git@bitbucket.org:myusername/#{application}.git"
set :branch, "master"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
######
set :rvm_ruby_string, 'ruby-1.9.3-p392' # use the same ruby as used locally for deployment
set :rvm_install_ruby_params, '--1.9' # for jruby/rbx default to 1.9 mode
set :rvm_install_pkgs, %w[libyaml openssl] # package list from https://rvm.io/packages
set :rvm_install_ruby_params, '--with-opt-dir=/usr/local/rvm/usr' # package support
before 'deploy:setup', 'rvm:install_rvm' # install RVM
before 'deploy:setup', 'rvm:install_pkgs' # install RVM packages before Ruby
before 'deploy:setup', 'rvm:install_ruby' # install Ruby and create gemset, or:
before 'deploy:setup', 'rvm:create_gemset' # only create gemset
before 'deploy:setup', 'rvm:import_gemset' # import gemset from file
########
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
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}"
sudo "mkdir -p #{shared_path}/config"
sudo "chown deployer:deployer #{shared_path}/config" # added this to get around sftp permisssions
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"
# sudo "chmod +x #{release_path}/config/unicorn_init.sh"
task :symlink_config, roles: :app do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
# run "chmod +x #{release_path}/config/unicorn_init.sh"
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
答案 0 :(得分:1)
尝试
chown -R deployer /home/deployer
答案 1 :(得分:0)
确保所有文件夹归部署者所有。 :)