Skip to content

Instantly share code, notes, and snippets.

@ruseel
Last active September 30, 2015 11:51
Show Gist options
  • Save ruseel/15e416c0bdf803f4408a to your computer and use it in GitHub Desktop.
Save ruseel/15e416c0bdf803f4408a to your computer and use it in GitHub Desktop.
여러 서버에 같은 명령을 내리는 방법

여러가지 Unix 도구가 있다. http://unix.stackexchange.com/a/19010

pssh
pdsh
clusterssh
clusterit
mussh

같은 명령만 실행시켜주는 것은 아니지만

capistrano
fabric

도 비슷한 용도로 쓸 수 있다. capistrano fabric은 배포용으로 주로 쓴다.

같은 명령만 할 때 capistrano v2에서는 cap shell을 입력하면 interactive하게 실행 가능하다.

Gemfile를 만들고

source 'https://rubygems.org'
gem 'capistrano', '~>2.15.0' 

bundle install 하고 bundle exec capify . 한 다음 config/deploy.rb를 고치고

default_run_options[:pty] = true
role :app, "host.a.com", "host.b.com" 
# role :app, *["host.a.com", "host.b.com"]

cap shell을 실행하면 interactive하게 command를 입력할 수 있다. 이게 가장 간편할 수 있다.

  task :task_a do
    run <<-EOF
      hostname
      sudo id
    EOF
  end 

이렇게 자주 실행하는 명령을 task로 deploy.rb안에 저장하고 bundle exec cap task_a로 실행할 수도 있다.

파일을 업로드 할 수 있다. FileUpload DSL

task :task_b do
  upload "myfile", "/tmp/full_path_in_server/myfile"
end

여기서 capistrano v3를 쓰지 않은 것은 cap shell 과 비슷한 코드를 capistrano3로 쓸 수 없어서다. (아직 어떻게 하는지 모른다.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment