0

Rails アプリケーションの cap/deploy スクリプトに取り組んでいます。私のサーバーでは、RVM を使用して Ruby のインストールを管理しています。

私が見ている問題は、ランナー/ユーザー/グループを正しいユーザーに設定したにもかかわらず、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
4

1 に答える 1

1

あなたのタスクinit_config:defaultには小さな追加が必要です:

    run "sudo chown -R #{user}:#{group} /home/#{user}/.rvm"
    run "gem install bundler"
于 2012-08-03T01:34:55.477 に答える