본문 바로가기

리눅스

Ubuntu에서 Supervisor를 설치하는 방법

728x90

Ubuntu에서 Supervisor를 설치하는 방법

Supervisor는 Linux 시스템에서 백그라운드 프로세스 및 작업을 관리하는 도구입니다

테스트 환경

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04 LTS
Release:	22.04
Codename:	jammy
  • apt 패키지 목록 업데이트
sudo apt-get update

supervisor 설치

  • supervisor 패키지 설치
sudo apt-get install -y supervisor
  • supervisor 버전 확인
supervisord --version
$ supervisord --version
4.2.1
  • supervisor 서비스를 시작하고 부팅 시 자동으로 시작하도록 활성화
systemctl --now enable supervisord
  • supervisord.conf 편집
vim /etc/supervisor/supervisord.conf
$ cat /etc/supervisor/supervisord.conf
; supervisor config file

[unix_http_server]
file=/var/run/supervisor.sock   ; (the path to the socket file)
chmod=0700                       ; sockef file mode (default 0700)

[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor            ; ('AUTO' child log dir, default $TEMP)

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket

; The [include] section can just contain the "files" setting.  This
; setting can list multiple files (separated by whitespace or
; newlines).  It can also contain wildcards.  The filenames are
; interpreted as relative to this file.  Included files *cannot*
; include files themselves.

[include]
files = /etc/supervisor/conf.d/*.conf
  • supervisord 데몬 재기동
systemctl --now enable supervisord
728x90
  • Supervisor 설정

Supervisor의 기본 설정 파일은 /etc/supervisor/supervisord.conf에 있습니다. 이 파일을 직접 편집하여 작업을 추가하거나 수정할 수 있지만, 이보다는 개별 작업용 설정 파일을 사용하는 것이 좋습니다.

개별 작업 설정 파일은 /etc/supervisor/conf.d/ 디렉토리에 생성하면 됩니다. .conf 확장자를 가진 파일이어야 합니다. 예를 들어, myapp.conf와 같은 이름으로 파일을 생성할 수 있습니다.

sudo nano /etc/supervisor/conf.d/myapp.conf
  • 내용 예시
[program:myapp]
command=/path/to/your/app
directory=/path/to/your/app/directory
autostart=true
autorestart=true
stderr_logfile=/var/log/myapp.err.log
stdout_logfile=/var/log/myapp.out.log
  • command: 실행할 명령이나 프로그램 경로를 지정합니다.
  • directory: 작업 디렉토리를 지정합니다.
  • autostart: 시스템 부팅 시 자동으로 시작할 지 여부를 결정합니다.
  • autorestart: 작업이 비정상 종료되었을 때 자동으로 재시작할 지 여부를 결정합니다.
  • stderr_logfile: 오류 로그 파일 경로를 지정합니다.
  • stdout_logfile: 표준 출력 로그 파일 경로를 지정합니다.
  • 작업 추가 및 적용

작업 설정 파일을 생성하고나면, 아래 명령을 통해 Supervisor에 작업을 추가하고 적용합니다.

sudo supervisorctl reread
sudo supervisorctl update

새 작업이나 변경된 설정이 적용됩니다.

 

  • 작업 제어

Supervisor를 통해 작업을 시작, 정지, 재시작하는 등의 명령을 사용할 수 있습니다.

 

  • 예를 들어
sudo supervisorctl start myapp
sudo supervisorctl stop myapp
sudo supervisorctl restart myapp

여기서 myapp는 작업 설정 파일에서 정의한 프로그램 이름입니다.

 

이제 Supervisor가 Ubuntu 시스템에 설치되었고, 작업을 추가하고 관리하는 방법을 알게 되었습니다. 원하는 작업을 설정하고 제어할 수 있을 것입니다.

 

참고URL

- How To Install supervisor on Ubuntu 22.04 : https://installati.one/install-supervisor-ubuntu-22-04/

 

728x90