supervisor 프로세스가 잘 돌고있는지.. 죽지 않았는지.. 확인하고 재구동 하는 일은 쉬운일이 아니다. 손쉽게 프로세스 상태를 보여주고, 죽은 프로세스도 자동으로 살려주는 유닉스계열의 시스템에서 동작하는 프로세스를 모니터링하고 관리하기 위한 클라이언트/서버 프로그램이다.
Supervisor is a client/server system that allows its users to control a number of processes on UNIX-like operating systems. It was inspired by the following:
http://supervisord.org/running.html
1) supervisord 설정
test@vm003:~$ cat /etc/supervisord.conf [inet_http_server] port=0.0.0.0:9001 username=usernameblabla password=passwordblabla |
inet_http_server 설정 내용이 들어있으면 웹브라우저에서 컨트롤이 가능하다.
웹브라우저로 vm003.server.host:9001 접속하면 설정에 있는 username/password물어보고 인증되면 웹어드민으로 접근가능하다
컨트롤은 재시작/상태/tail로그 를 할수있다
설정을 변경했다면, supervisor자체를 stop / start 해서 다시 띄운다.
sudo /etc/init.d/supervisord stop
sudo /etc/init.d/supervisord start
[include] files = /etc/supervisor/conf.d/*.conf |
로 프로그램설정을 인클루드 해서 관리 할수있다.
아래설정파일처럼 인클루드한 디렉터리에 프로세스별 설정.conf파일을 관리 한다.
이 설정은 my_app.py 프로세스를 띄우는 설정으로 program: 이름은 my-app으로 뜬다.
각각의 프로그램을 그룹으로 설정해서 관리 할수도 있다. 그룹으로 관리 하면
supervisorctl restart groupname:* 으로 그룹단위로 관리할수있는게 장점이다.
server@vm003:/etc/supervisor/conf.d$ cat my-app.conf [program:my-app] autostart=true autorestart=true numprocs=1 numprocs_start=1 stopasgroup=true killasgroup=true user=server umask=022 priority=910 process_name=%(program_name)s-%(process_num)s directory=/myapp/mydirectory/current command=/myapp/mydirectory/current/venv/bin/python workers/events/my_app.py alpha.yml environment=PYTHONPATH=/myapp/mydirectory/current stdout_events_enabled=true stderr_events_enabled=true logfile_maxbytes=5MB logfile_backups=1 redirect_stderr=true stdout_logfile=/var/log/path/%(program_name)s-%(process_num)s.log |
program셋팅관련된 설명은 http://supervisord.org/configuration.html#program-x-section-settings 을 참고하면 되고, 설정내용이 변경됐을때는 reread 를 통해 변경된 프로그램을 한번더 확인할수있고, update로 반영해줄수 있다.
server@vm003:/etc/supervisor/conf.d$ sudo supervisorctl reread No config updates to processes server@vm003:/etc/supervisor/conf.d$ sudo supervisorctl update |
이때 program.conf파일에 autostart , autorestart:true로 되어있으면 설정에 맞게 오토로 컨트롤할수있다.
이 외에도
systemd https://www.freedesktop.org/wiki/Software/systemd/
circus http://circus.readthedocs.io/en/latest/ 는 16년이 마지막이고
upstart http://upstart.ubuntu.com/
runit http://smarden.org/runit/ 등 도 있다.
'파이썬' 카테고리의 다른 글
파이썬_최적화튜닝전략 (0) | 2016.09.02 |
---|---|
memcache클러스터구성 (python-memcache 패키지) (0) | 2016.06.03 |
effective pyton 을 읽고 (0) | 2016.05.16 |
cheaper-busyness-backlog-alert (0) | 2016.03.10 |
with문은 시작 시점에 해당 클래스의 __enter__(self) 메쏘드를 호출해주고, with문 끝에 __exit__(type, value, traceback)메쏘드를 호출 (0) | 2016.01.05 |