2012-08-02 109 views
0

我正在爲我的rails應用程序使用cap/deploy腳本。在我的服務器上,我使用RVM來管理我的ruby安裝。捆綁軟件安裝權限問題

即使我將runner/user/group設置爲正確的用戶,但我看到的問題是,當我嘗試安裝gem時,出現權限錯誤。

這是我看到的錯誤:

** loading stage recipe 'deploy' 
** loading stage recipe 'init_config' 
** loading stage recipe 'nginx' 
executing locally: "git ls-remote ############################### ec2" 
command finished in 1113ms 
* executing `deploy:setup' 
triggering before callbacks for `deploy:setup' 
* executing `init_config' 
* executing "whoami" 
servers: ["ec2-23-23-24-42.compute-1.amazonaws.com"] 
[ec2-23-23-24-42.compute-1.amazonaws.com] executing command 
** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] ubuntu 
command finished in 529ms 
* executing "gem install bundler" 
servers: ["ec2-23-23-24-42.compute-1.amazonaws.com"] 
[ec2-23-23-24-42.compute-1.amazonaws.com] executing command 
** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] ERROR: While executing gem ... (Gem::FilePermissionError) 
** [out :: ec2-23-23-24-42.compute-1.amazonaws.com] You don't have write permissions into the /home/ubuntu/.rvm/gems/ruby-1.9.2-p290 directory. 
command finished in 1026ms 
*** failed: "bash --login -c 'gem install bundler'" on ec2-23-23-24-42.compute-1.amazonaws.com 

這是我出口上限文件:

load 'deploy' 

# ================================================================ 
# ROLES 
# ================================================================ 


role :app, "ec2-23-23-24-42.compute-1.amazonaws.com" 


# ================================================================ 
# VARIABLES 
# ================================================================ 

# Webistrano defaults 
    set :webistrano_project, "sweet_high" 
    set :webistrano_stage, "staging" 


    set :application, "" 

    set :branch, "ec2" 

    set :bundle_disable_shared_gems, "\"1\"" 

    set :bundle_path, "vendor/bundler_gems" 

    set :default_shell, "bash --login" 

    set :deploy_to, "/data/\#{application}" 

    set :deploy_via, :remote_cache 

    set :domain, "" 

    set :environment, "staging" 

    set :group, "ubuntu" 

    set :nginx_conf_path, "/etc/nginx/sites-enabled" 

    set :password, "deployment_user(SSH user) password" 

    set :rails_env, "staging" 

    set :repository, "t" 

    set :runner, "ubuntu" 

    set :rvm_bin_path, "/home/#{user}/.rvm/bin/rvm" 

    set :rvm_type, :user 

    set :scm, :git 

    set :scm_password, "your_SVN_password" 

    set :scm_username, "your_SVN_user" 

    set :ssh_options, {:forward_agent => true,:paranoid => false,:keys => ["/home/#{user}/.ssh/rails_app_server.pem"]} 

    set :use_sudo, true 

    set :user, "ubuntu" 




# ================================================================ 
# TEMPLATE TASKS 
# ================================================================ 

    # allocate a pty by default as some systems have problems without 
    default_run_options[:pty] = true 

    # set Net::SSH ssh options through normal variables 
    # at the moment only one SSH key is supported as arrays are not 
    # parsed correctly by Webistrano::Deployer.type_cast (they end up as strings) 
    [:ssh_port, :ssh_keys].each do |ssh_opt| 
     if exists? ssh_opt 
     logger.important("SSH options: setting #{ssh_opt} to: #{fetch(ssh_opt)}") 
     ssh_options[ssh_opt.to_s.gsub(/ssh_/, '').to_sym] = fetch(ssh_opt) 
     end 
    end 



# ================================================================ 
# CUSTOM RECIPES 
# ================================================================ 


before "deploy:setup", :init_config 
after "deploy:setup", :setup_cleanup 
namespace :init_config do 
    desc <<-DESC 
     Created directory structure, changes ownership, etc... 
    DESC 

    task :default do 
     run "gem install bundler" 
     run "sudo mkdir -p #{deploy_to}" 
     run "sudo chown -R #{user}:#{group} #{deploy_to}" 
     run "mkdir -p #{shared_path}/config" 
     run "mkdir -p #{shared_path}/config" 
     File.open("/home/#{user}/.ssh/id_rsa", "rb").each_line{ |line| 
      run "echo #{line} >> ~/.ssh/id_rsa" 
     } 
     run "chown #{user}:#{group} ~/.ssh/id_rsa" 
     run "chmod 600 ~/.ssh/id_rsa"  
    end 
end 

回答

1

你的任務init_config:default需要添加少量:

run "sudo chown -R #{user}:#{group} /home/#{user}/.rvm" 
    run "gem install bundler" 
+0

我完全錯過那。感謝您的幫助。 – rottmanj 2012-08-03 18:33:55