본문 바로가기

도구의발견

중앙 집중형 deploy tool - "Fabric"

만일 현재 사용하고 계신 바이너리 & 설정 deploy tool이 없다면 'Fabric(http://docs.fabfile.org/en/1.7/)' 이라는 녀석을 한번 살펴 보실것을 권해 드립니다.

 

What is "Fabric"?

Fabric is a Python (2.5 or higher) library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks. - http://docs.fabfile.org/en/1.7/

간단하게 어플리케이션 배포나 시스템 관리를 위해 사용되는 툴이랍니다. 뭔 말인가 싶어 다른 검색을 좀더 해봅니다.

You can use Fabric as a tool for centralized configuration management. You can run administrative tasks on all of your machines simultaneously. - http://awaseroot.wordpress.com/2012/04/23/fabric-tutorial-1-take-command-of-your-network/

중앙 집중형 설정 및 디스트 관리 도구, 로컬 머신에서 리모트 머신의 어드민 작업을 할수 있답니다.

 

사족을 달자면..

- install 외에 별다른 설정 없음.

- python 기반

 

Install :

$ sudo apt-get install fabric
- 위와 같이하면 그냥 깔립니다. 설치의 모든 과정이 끝났습니다.

 

Quick Sample :

// fabfile.py
from fabric.api import run, env, execute, task
from fabric.operations import local, put

#환경 설정
env.hosts = ['some1.host.com',
                   'some2.host.com',
                   'some3.host.com'
                  ]


env.user = 'user_account'
env.password = 'password_boo'

def stop() :
           run ('/etc/init.d/deamon stop')

def copy() :
           put('./etc/init.d/daemon, '/etc/init.d/daemon') #로컬의 바이너리를 리모트로 복사

def start() :
           run ('/etc/init.d/deamon start')

def deploy() :
           execute(stop)
           execute(copy)
           execute(start)

 

 

간단하게 서버에 접속 해서 데몬을 stop 시키고, 로컬에 있는 바이너리를 리모트로 복사 그리고 재시작하는 스크립트를 작성했습니다.


- 파일 이름을 반드시 fabfile.py로 해야함.
- env : 환경 변수. 각종 설정 내용들이 들어감(서버 리스트, 아이디, 패스워드 등등..)

  (http://docs.fabfile.org/en/1.7/usage/env.html)
- run : 리모트 실행
- put : 로컬 -> 리모트 파일 복사
- execute : 로컬 함수 실행

  (http://docs.fabfile.org/en/1.7/usage/execution.html#execution-strategy)

 

How to Run :

$ fab deploy

위 과정을 거치면 실행 인자의 deploy 함수를 수행하면서 원격 머신(some1~3)의 실행중인 바이너리를 종료하고,
지정된 파일을 복사후 재시작 하게 됩니다.

 

ref.
- fabric official site : http://docs.fabfile.org/en/1.7/
- fabric tutorial site : http://awaseroot.wordpress.com/2012/04/23/fabric-tutorial-1-take-command-of-your-network/

 

 

유익한 글이었다면 공감(❤) 버튼 꾹!! 추가 문의 사항은 댓글로!!