문제

나는 실행하려고 카피스트라노 3 절에서 작업과 같은 단계를 다른 ssh_options.

나의 생산.rb 말:

이 구성과 카피스트라노에 연결된 사용자 배포 는 올바른의 나머지 부분에 대한 taks.그러나 나는 그것을 연결할 필요가 중 하나에 대한 특정 작업 an_other_user wich 은 구성에서는 서버입니다.다음 내 말:

실행할 때:

캡 생산 네임스페이스:my_task_with_an_other_user

카피스트라노 만들 ssh 연결 원:사용자"배포"(사용자 선언에서 생산입니다.rb).

어떻게 사용자를 변경 및/또는 ssh_options 내부 작업은?

도움이 되었습니까?

해결책

카피스트라노 3

나는 힘든 시간을 찾는 솔루션입니다.그러나 솔루션보다 훨씬 좋네요 버전 2.모자 팀이 수행한 작업입니다.는지 확인 업데이트되어 있는 카피스트라노 3.2.x+여기에 속:

# in config/deploy/production.rb, or config/deploy/staging.rb
# These roles are used for deployment that works with Cap hooks
role :app, %w{deploy@myserver.com}
role :web, %w{deploy@myserver.com}
role :db,  %w{deploy@myserver.com}

# Use additional roles to run side job out side Capistrano hooks
# 'foo' is another ssh user for none-release purpose tasks (mostly root tasks).
# e.g. user 'deploy' does not have root permission, but 'foo' has root permission.
# 'no_release' flag is important to flag this user will skip some standard hooks
# (e.g. scm/git/svn checkout )
role :foo_role, %w{foo@myserver.com}, no_release: true

는지 확인 모두'배포'&'foo'사용자 수 있습 ssh 으로합니다.내에서의 작업,사용 on 키워드:

task :restart do
  on roles(:foo_role) do
    sudo "service nginx restart"
  end
end

task :other_standard_deployment_tasks do
  on release_roles(:all) do
     # ...
  end
end

다른 문제점:

어떤 확인 카피스트라노의 작업에 건너뛰 추가 없음 릴리스 역할을 할 수 있습니다.그렇지 않으면,그것을 일으킬 수 있 파일 권한 문제를 배포하는 동안.E.g. capistrano/bundler 확장자를 재정의해야 할 기본 bundler_roles

set :bundler_roles, %w(web app db)  # excludes the no release role.

카피스트라노 2

내가 사용하는 사용자 정의 기능을 닫고 다시 연결하는 ssh 세션이 있습니다.

다음 방법 deploy.rb.전화 with_user 스 ssh 세션이 있습니다.약간의 단순화 버전:

def with_user(new_user, &block)
  old_user = user
  set :user, new_user
  close_sessions
  yield
  set :user, old_user
  close_sessions
end

def close_sessions
  sessions.values.each { |session| session.close }
  sessions.clear
end

사용법:

task :update_nginx_config, :roles => :app do
  with_user "root" do
    sudo "nginx -s reload"
  end
end

다른 팁

@activars에 대한 답변이 나를 위해 작동하지 않았습니다.내가 한 환경에 대해 몇 가지 역할을 정의했을 때 - 하나만 배포 되었기 때문에 : (

이 해결책은 여러 가지 환경을 만드는 것이 었습니다. production.rb 생산 root.rb

프로덕션 루트에는 no_release= true 플래그가있는 내용이 있습니다. 지정한대로 :

server '146.120.89.81', user: 'root', roles: %w{foo_role}, no_release: true
.

그 후

를 실행하는 SH 스크립트를 만들었습니다.
#/usr/bin/env bash
bundle exec cap production deploy
bundle exec cap productionroot deploy
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top