Capistrano无法创建符号链接:文件存在

时间:2014-11-24 14:39:07

标签: ruby-on-rails capistrano web-deployment capistrano3

我有Capistrano 3的Rails 4应用程序。

# deploy.rb
set :application, '<DELETED>'
set :user, '<DELETED>'
set :repo_url, '<DELETED>'
set :branch, 'master'
ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }

set :deploy_to, "/home/#{fetch :user}/apps/#{fetch :application}"
set :scm, :git

set :format, :pretty
set :log_level, :debug
set :pty, true

set :linked_files, %w{config/application.yml}
set :linked_dirs, %w{bin log tmp vendor/bundle public/system public/deploy}

# set :default_env, { path: "/opt/ruby/bin:$PATH" }
set :keep_releases, 5

namespace :deploy do

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      # Your restart mechanism here, for example:
      # execute :touch, release_path.join('tmp/restart.txt')
      within fetch :current_path do
        execute "/etc/init.d/unicorn_#{fetch :application} restart"
      end
    end
  end

  before :restart, 'rvm:hook'

  desc 'Stop application'
  task :stop do
    on roles(:app), in: :sequence, wait: 5 do
      # Your restart mechanism here, for example:
      within fetch :current_path do
        execute "/etc/init.d/unicorn_#{fetch :application} stop"
      end
      # execute :touch, release_path.join('tmp/restart.txt')
    end
  end
  before :stop, 'rvm:hook'

  desc 'Start application'
  task :start do
    on roles(:app), in: :sequence, wait: 5 do
      # Your restart mechanism here, for example:
      within fetch :current_path do
        execute "/etc/init.d/unicorn_#{fetch :application} start"
      end
      # execute :touch, release_path.join('tmp/restart.txt')
    end
  end
  before :start, 'rvm:hook'
  before 'whenever:update_crontab', 'rvm:hook'
  before 'whenever:clear_crontab', 'rvm:hook'

  after :finishing, 'deploy:cleanup'
  after :finished, 'deploy:restart'

  task :add_default_hooks do
    after 'deploy:starting', 'sidekiq:quiet'
    after 'deploy:updated', 'sidekiq:stop'
    after 'deploy:reverted', 'sidekiq:stop'
    after 'deploy:published', 'sidekiq:start'
  end

end

部署生产设置:

# production.rb
set :stage, :production

# Simple Role Syntax
# ==================
# Supports bulk-adding hosts to roles, the primary
# server in each group is considered to be the first
# unless any hosts have the primary property set.
role :app, %w{<DELETED>}
role :web, %w{<DELETED>}
role :db,  %w{<DELETED>}

# Extended Server Syntax
# ======================
# This can be used to drop a more detailed server
# definition into the server list. The second argument
# something that quacks like a hash can be used to set
# extended properties on the server.
server '128.199.148.191', user: 'deployer', roles: %w{web app db} #, my_property: :my_value
set :rvm_type, :system
set :rvm_ruby_version, '2.1.0'
set :rails_env, 'production'
# you can set custom ssh options
# it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options
# you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start)
# set it globally
#  set :ssh_options, {
#    keys: %w(/home/rlisowski/.ssh/id_rsa),
#    forward_agent: false,
#    auth_methods: %w(password)
#  }
# and/or per server
# server 'example.com',
#   user: 'user_name',
#   roles: %w{web app},
#   ssh_options: {
#     user: 'user_name', # overrides user setting above
#     keys: %w(/home/user_name/.ssh/id_rsa),
#     forward_agent: false,
#     auth_methods: %w(publickey password)
#     # password: 'please use keys'
#   }
# setting per server overrides global ssh_options

# fetch(:default_env).merge!(rails_env: :production)
set :ssh_options, {
                    auth_methods: %w(publickey password),
                    user: '<DELETED>'
                }

没关系,但我有创建符号链接的问题。它返回'file exists',但我没有在存储库中创建application.yml或public / system forlder,只在共享文件夹中创建。 记录:

 INFO[3e66cb56] Finished in 0.842 seconds with exit status 0 (successful).
** Invoke deploy:symlink:shared (first_time)
** Execute deploy:symlink:shared
** Invoke deploy:symlink:linked_files (first_time)
** Execute deploy:symlink:linked_files
INFO[146e0a26] Running /usr/bin/env mkdir -p /home/deployer/apps/xxxcoast/releases/20141124144030/config on 128.199.148.191
DEBUG[146e0a26] Command: /usr/bin/env mkdir -p /home/deployer/apps/xxxcoast/releases/20141124144030/config
INFO[a9a9bef0] Running /usr/bin/env mkdir -p /home/deployer/apps/xxxcoast/releases/20141124144030/config on 128.199.148.191
DEBUG[a9a9bef0] Command: /usr/bin/env mkdir -p /home/deployer/apps/xxxcoast/releases/20141124144030/config
INFO[a9a9bef0] Finished in 0.848 seconds with exit status 0 (successful).
INFO[146e0a26] Finished in 0.850 seconds with exit status 0 (successful).
DEBUG[0f26dfb7] Running /usr/bin/env [ -L /home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml ] on 128.199.148.191
DEBUG[2d8972f0] Running /usr/bin/env [ -L /home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml ] on 128.199.148.191
DEBUG[0f26dfb7] Command: [ -L /home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml ]
DEBUG[2d8972f0] Command: [ -L /home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml ]
DEBUG[2d8972f0] Finished in 0.822 seconds with exit status 1 (failed).
DEBUG[7858afe7] Running /usr/bin/env [ -f /home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml ] on 128.199.148.191
DEBUG[7858afe7] Command: [ -f /home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml ]
DEBUG[0f26dfb7] Finished in 0.827 seconds with exit status 1 (failed).
DEBUG[7e5cbc1c] Running /usr/bin/env [ -f /home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml ] on 128.199.148.191
DEBUG[7e5cbc1c] Command: [ -f /home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml ]
DEBUG[7e5cbc1c] Finished in 0.838 seconds with exit status 1 (failed).
INFO[9cc3b7d0] Running /usr/bin/env ln -s /home/deployer/apps/xxxcoast/shared/config/application.yml /home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml on 128.199.148.191
DEBUG[9cc3b7d0] Command: /usr/bin/env ln -s /home/deployer/apps/xxxcoast/shared/config/application.yml /home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml
DEBUG[7858afe7] Finished in 0.843 seconds with exit status 1 (failed).
INFO[bcf64145] Running /usr/bin/env ln -s /home/deployer/apps/xxxcoast/shared/config/application.yml /home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml on 128.199.148.191
DEBUG[bcf64145] Command: /usr/bin/env ln -s /home/deployer/apps/xxxcoast/shared/config/application.yml /home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml
INFO[9cc3b7d0] Finished in 1.032 seconds with exit status 0 (successful).
DEBUG[bcf64145]     ln: failed to create symbolic link ‘/home/deployer/apps/xxxcoast/releases/20141124144030/config/application.yml’: File exists
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host 128.199.148.191: ln exit status: 1
ln stdout: Nothing written
ln stderr: Nothing written
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/command.rb:97:in `exit_status='
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:148:in `block (5 levels) in _execute'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:551:in `call'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:551:in `do_request'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:561:in `channel_request'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:221:in `preprocess'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:205:in `process'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `block in loop'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:269:in `wait'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:170:in `block (3 levels) in _execute'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:514:in `call'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:514:in `do_open_confirmation'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:545:in `channel_open_confirmation'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:221:in `preprocess'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:205:in `process'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `block in loop'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:172:in `block (2 levels) in _execute'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:186:in `with_ssh'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:131:in `block in _execute'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `tap'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `_execute'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:66:in `execute'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/bundler/gems/capistrano-52591324f3ae/lib/capistrano/tasks/deploy.rake:129:in `block (5 levels) in <top (required)>'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/bundler/gems/capistrano-52591324f3ae/lib/capistrano/tasks/deploy.rake:122:in `each'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/bundler/gems/capistrano-52591324f3ae/lib/capistrano/tasks/deploy.rake:122:in `block (4 levels) in <top (required)>'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `run'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
SSHKit::Command::Failed: ln exit status: 1
ln stdout: Nothing written
ln stderr: Nothing written
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/command.rb:97:in `exit_status='
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:148:in `block (5 levels) in _execute'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:551:in `call'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:551:in `do_request'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:561:in `channel_request'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:221:in `preprocess'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:205:in `process'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `block in loop'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:269:in `wait'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:170:in `block (3 levels) in _execute'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:514:in `call'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:514:in `do_open_confirmation'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:545:in `channel_open_confirmation'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:221:in `preprocess'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:205:in `process'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `block in loop'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:172:in `block (2 levels) in _execute'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:186:in `with_ssh'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:131:in `block in _execute'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `tap'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `_execute'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:66:in `execute'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/bundler/gems/capistrano-52591324f3ae/lib/capistrano/tasks/deploy.rake:129:in `block (5 levels) in <top (required)>'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/bundler/gems/capistrano-52591324f3ae/lib/capistrano/tasks/deploy.rake:122:in `each'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/bundler/gems/capistrano-52591324f3ae/lib/capistrano/tasks/deploy.rake:122:in `block (4 levels) in <top (required)>'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `run'
/Users/quatermain/.rvm/gems/ruby-2.1.0@xxxcoast/gems/sshkit-1.5.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
Tasks: TOP => deploy:symlink:linked_files
The deploy has failed with an error: Exception while executing on host 128.199.148.191: ln exit status: 1
ln stdout: Nothing written
ln stderr: Nothing written
** Invoke deploy:failed (first_time)
** Execute deploy:failed

编辑:更好的日志

3 个答案:

答案 0 :(得分:3)

我发现这是因为我有重复的角色定义,因此它运行了两次symlink命令。

检查您是否没有重复的role行,或者您还拥有role行,以及一对一server配置行。

答案 1 :(得分:1)

我认为在我的情况下是双重命令:

ln -s with "exit status 0", and next 
ln -s with "exit status 1" and with information "file exists" 

是由于在config / deploy / production.yml

中将IP服务器更改为DNS名称引起的
-role :app, %w{appuser@example.com}
-role :web, %w{appuser@example.com}
-role :db,  %w{appuser@example.com}
+role :app, %w{appuser@1.2.3.4}
+role :web, %w{appuser@1.2.3.4}
+role :db,  %w{appuser@1.2.3.4}

我不确定这是唯一一次更改,但是当我回滚此更改(再次转到dns地址)时,没有更多的命令。它看起来像capistrano缓存或存储旧配置..我发现了这一点,因为我预计日志中只有IP,但我在部署日志中看到了:

INFO [d2ac8c5x] Running /usr/bin/env git remote update as appuser@example.com
INFO [3fe766d1] Running /usr/bin/env git remote update as appuser@1.2.3.4

答案 2 :(得分:0)

您的config/application.yml可能存在于存储库中,这导致了问题。如果目标已存在,ln -s将不会创建符号链接。

Flag -L检查给定路径是否为符号链接。在这种情况下,它返回退出代码1,因为它不是。

相关问题