반응형
systemd 서비스 파일 생성
/etc/systemd/system/django.service
etc 파일이 root 권한으로 설정되어 있기 때문에, cat 명령어를 이용하여 파일 생성 후, sudo를 이용하여 파일을 이동시켜주어야 한다.
[Unit]
# 서비스에 대한 설명과 의존성을 정의
Description=django daemon by gunicorn
# 네트워크 서비스가 필요함을 의미
After=network.target
[Service]
# 서비스 실행에 필요한 설정
User=ubuntu
Group=ubuntu
WorkingDirectory=/srv/course-repo/myproj
ExecStart=/srv/venv/bin/gunicorn \
--config /srv/config/gunicorn.conf.py \
--env ENV_PATH=/srv/config/django.env \
mysite.wsgi:application
[Install]
# 멀티 유저 모드로 전환될 때 자동으로 시작되어야 함을 의미
WantedBy=multi-user.target
/srv/config/gunicorn.conf.py
bind = "0.0.0.0:8080"
# refs: https://docs.gunicorn.org/en/stable/settings.html
systemd 서비스 등록
# 서비스 파일 다시 읽기. 서비스 파일 수정 후에 실행 필요.
$ sudo systemctl daemon-reload
# 서비스를 활성화하여 부팅 시 자동 시작하도록 설정
$ sudo systemctl enable django.service
# Created symlink /etc/systemd/system/multi-user.target.wants/django.service → /etc/systemd/system/django.service.
# 서비스 시작
$ sudo systemctl start django.service
# 서비 상태 확인
$ sudo systemctl status django.service
# 서비스 재시작
$ sudo systemctl restart django.service
# 서비스 중지
$ sudo systemctl stop django.service
# 서비스 로그 확인
$ sudo journalctl -u django.service
# 서비스 로그 실시간 확인
$ sudo journalctl -u django.service -f
# 특정 시간 이후의 로그 확인 (역순은 -r 옵션, 실시간은 -f 옵션)
$ sudo journalctl -u django.service --since "2024-01-01 00:00:00"
# 특정 시간 이전의 로그 확인
$ sudo journalctl -u django.service --until "2024-01-01 00:00:00"
서버 시간대 변경하기 (UTC -> Asia/Seoul)
sudo timedatectl show
sudo timedatectl set-timezone Asia/Seoul
반응형
'Django > 인프라' 카테고리의 다른 글
[Nginx] Nginx를 경유해서 장고로 요청 전달하기 (0) | 2024.08.06 |
---|---|
[Nginx] Nginx란 무엇인가? (0) | 2024.08.06 |
[AWS Lightsail] 가상환경 생성 및 패키지 설치 (0) | 2024.08.06 |
[AWS Lightsail] 비공식 PPA를 통한 파이썬 설치하기 (3.12) (0) | 2024.08.06 |
[AWS Lightsail] 리눅스 가상머신 생성 (0) | 2024.08.06 |