[Rails] seesaw 사용해서 서비스를 우아하게 재시작하기
seesaw 는 ?
mongrel은 rails를 위한 서버로 가장 많이 사용되는 서버일 것이다. 보통 mongrel을 여러개 실행시키고 apache나 nginx를 reverse proxy server 로 사용할텐데, mongrel 프로세스들을 관리하기 위해 mongrel_cluster를 사용한다. mongrel_cluster를 사용하면 여러개의 mongrel들을 손쉽게 실행시키고 중지시킬 수 있다.
mongrel_cluster가 편하기는 하지만 실제 서비스를 할 때는 걱정거리가 있는데, 그것은 서비스를 재시작할 때다. 서비스의 기능이 개선되어 소스를 update하고 싶을 때, 서비스의 중단없이 이것이 가능할까? seesaw를 사용하면 가능하다.
시나리오
mongrel_rails seesaw:bounce 를 실행하면 다음과 같은 일들이 벌어진다.
- webserver의 설정이 앞의 절반의 mongrel을 사용하도록 변경된다.
- webserver가 우아하게 재시작된다.
- 뒤의 절반의 mongrel들이 재시작된다.
- webserver의 설정이 뒤의 절반의 mongrel들을 사용하도록 변경된다.
- webserver가 우아하게 재시작된다.
- 앞의 절반의 mongrel들이 재시작된다.
- webserver의 설정이 모든 mongrel들을 사용하도록 변경된다.
- webserver가 우아하게 재시작된다.
가정
mongrel과 mongrel_cluster를 사용한다.
설치
- gem install seesaw
환경 설정
- mongrel_rails seesaw::configure
위명령은 config/seesaw.yml과 config/http_cluster 디렉토리에 cluster_all.conf, cluster_1.conf, cluster_2.conf, cluster.conf를 생성시킨다.
- seesaw.yml은 seesaw 명령을 수행하는 데 필요한 설정이 있다.
- cluster_all.conf 는 apache가 모든 mongrel들을 사용하도록 하는 proxy balancer 설정이 있다.
- cluster_1.conf, cluster_2.conf는 apache가 앞/뒤의 절반의 mongrel들을 사용하도록 하는 proxy balancer 설정이 있다.
- cluster.conf는 cluster_xxx.conf에 대한 symbolic link이다.
config/http_cluster 디렉토리를 server의 적당한 곳에 이동시키자.
capistrano를 사용한다면 shared 에 놓는 것도 좋을듯 싶다.
config/seesaw.yml 를 편집하자.
- restart_cmd: sudo apache2ctl graceful
config_symlink: cluster.conf
mongrel_config_path: config/mongrel_cluster.yml
config_path: /PATH/TO/HTTP_CLUSTER/http_cluster
config_files:
all: cluster_all.conf
1: cluster_1.conf
2: cluster_2.conf
symlink_cmd: sudo ln -sf
- apache2를 사용하고 있다면 restart_cmd 가 apache2ctl graceful 이다.
- sudo를 이용하고 있다면 symlink_cmd 에 sudo를 넣어 두자. 아니라면 파일 소유자와 권한을 신경써 주어야 한다.
- config_path에는 http_cluster의 directory를 적어주자.
- mongrel_config_path : mongrel_cluster.yml 의 위치를 가르키고 있지만, seesaw는 참조하지 않는 쓸모없는 설정이다. mongrel_cluster.yml의 위치를 seesaw에게 알려주고 싶다면 mongrel_config_path 대신 mongrel_config_file을 사용해야 한다. 왜 참조하지도 않는 것을 default 설정에 넣어놨을까.. 바보 seesaw.
Apache2 설정
Apache 설정 중 Proxy balancer 대신 다음을 추가하자. apache의 설정은 [Rails] Windeow에서 apache + proxy_balancer 사용하기 를 참조
- Include "/home/APP_NAME/shared/http_cluster/cluster.conf"
cluster_all.conf, cluster_1.conf, cluster_2 를 열어서
proxy_balancer 이름을 수정해 주자.
- <Proxy balancer://MY_APP_mongrel_packs>
실행
실행은 간단하다.
- mongrel_rails seesaw:bounce
capistrano를 이용해서 배포를 하고 있다면 [Rails] Capistrano와 seesaw를 이용해서 배포하기 를 참조한다.
Comments (0)