Kallithea를 Daemon service 로 등록하기

김태호·2022년 5월 4일
0

Kallithea

목록 보기
5/5

문서 내용

systemd 에 python (venv) 서비스 등록
SSH를 종료하면 venv 프로세스가 종료되는 현상이 발생하여 Kallithea를 자동으로 시작하는 서비스를 등록하기로 함.


권장사항

Kallithea 는 Unix/Linux 환경에 설치를 진행할 경우 가상환경 (Virtual environment)을 이용할것을 가장 권장한다.

그 이유는 다음과 같다:

Kallithea 설치에 별도의 Virtual Environment (가상환경)을 사용하는 것이 좋습니다.
이렇게 하면 Kalithea에 필요한 모든 라이브러리는 기본 Python 설치와 별도로 설치되고 다른 응용 프로그램 및 Kalithea를 업그레이드할 때 문제가 덜 발생합니다.
가상 환경의 또 다른 이점은 루트 권한이 필요하지 않다는 것입니다.

작업 내용

Kallithea 전용 EC2 인스턴스 Kallithea 설치 경로
/path/to/kallithea_070 내부에서 kallithea_070 가상환경을 사용하여 서버를 실행시킴

/etc/systemd/system 경로에 .service 파일 만들기

kallithea@aws-ec2-server:/etc/systemd/system$ cat kallithea.service
# vi /etc/systemd/system/kallithea.service
 
[Unit]
Description=Kallithea SCM
After=network.target
 
[Service]
Type=simple
# 서비스로 동작하면 /data 또는 /repos 중 일부 파일의 소유권이 root 로 저장됩니다.
# 유지보수 및 테스트 환경에서는 사용자 및 그룹을 ubuntu 로 설정해서 사용하시길 바랍니다.
# User=root
# Group=root
User=ubuntu
Group=ubuntu
ExecStart=/bin/sh /path/to/kallithea_070/start-kallithea.sh
TimeoutSec=600
Restart=on-failure
RuntimeDirectoryMode=755
 
[Install]
WantedBy=multi-user.target

start-kallithea.sh 작성 내용

/path/to/kallithea_070:~/kallithea_070$ cat start-kallithea.sh
#!/bin/bash
 
echo "Kallithea is running"
. "/path/to/kallithea_070/bin/activate"
gearbox serve -c /path/to/kallithea_070/kallithea.ini

권한 변경

# start-kallithea 권한
kallithea@aws-ec2-server:~$ chmod 755 /home/ubuntu/kallithea_070/start-kallithea.sh
 
# kallithea.service 소유 및 권한
kallithea@aws-ec2-server:~$ sudo chmod 755 /etc/systemd/system/kallithea.service
kallithea@aws-ec2-server:~$ sudo chown root:root /etc/systemd/system/kallithea.service

Kallithea 서비스 등록 및 실행

kallithea@aws-ec2-server:~$ sudo systemctl enable kallithea.service
kallithea@aws-ec2-server:~$ sudo systemctl daemon-reload
kallithea@aws-ec2-server:~$ sudo systemctl start
kallithea@aws-ec2-server:~$ sudo systemctl start kallithea.service
kallithea@aws-ec2-server:~$ sudo systemctl status kallithea.service
● kallithea.service - Kallithea SCM
     Loaded: loaded (/etc/systemd/system/kallithea.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2021-06-09 01:37:13 UTC; 2h 6min ago
   Main PID: 339830 (sh)
      Tasks: 2 (limit: 4638)
     Memory: 81.6M
     CGroup: /system.slice/kallithea.service
             ├─339830 /bin/sh /path/to/ubuntu/kallithea_070/start-kallithea.sh
             └─339833 /path/to/kallithea_070/bin/python3 /path/to/kallithea_070/bin/gearbox serve -c /path/to/kallithea_070/kallithea.ini
 
Jun 09 03:43:07 aws-ec2-server sh[339833]: 2021-06-09 03:43:07.758 DEBUG [sqlalchemy.engine.base.Engine] Row (125, 18, 4, 197, 4, 'repository.write', 35, >
Jun 09 03:43:07 aws-ec2-server sh[339833]: 2021-06-09 03:43:07.758 DEBUG [sqlalchemy.engine.base.Engine] Row (148, 18, 4, 214, 4, 'repository.write', 35, >
Jun 09 03:43:07 aws-ec2-server sh[339833]: 2021-06-09 03:43:07.758 DEBUG [sqlalchemy.engine.base.Engine] Row (143, 18, 4, 210, 4, 'repository.write', 48, >
Jun 09 03:43:07 aws-ec2-server sh[339833]: 2021-06-09 03:43:07.763 INFO  [sqlalchemy.engine.base.Engine] SELECT repo_to_perm.repo_to_perm_id AS repo_to_pe>
Jun 09 03:43:07 aws-ec2-server sh[339833]: FROM repo_to_perm LEFT OUTER JOIN repositories AS repositories_1 ON repositories_1.repo_id = repo_to_perm.repos>
Jun 09 03:43:07 aws-ec2-server sh[339833]: WHERE repo_to_perm.user_id = %(user_id_1)s
Jun 09 03:43:07 aws-ec2-server sh[339833]: 2021-06-09 03:43:07.763 INFO  [sqlalchemy.engine.base.Engine] {'user_id_1': 39}
Jun 09 03:43:07 aws-ec2-server sh[339833]: 2021-06-09 03:43:07.764 DEBUG [sqlalchemy.engine.base.Engine] Col ('repo_to_perm_repo_to_perm_id', 'repo_to_per>
Jun 09 03:43:07 aws-ec2-server sh[339833]: 2021-06-09 03:43:07.765 DEBUG [kallithea.lib.auth] Middleware check areum for {'repository.write', 'repository.>
Jun 09 03:43:07 aws-ec2-server sh[339833]: 2021-06-09 03:43:07.765 INFO  [kallithea.controllers.base] pull action on git repo "Hicare-Smart/v3/HicareM" by>
lines 1-20/20 (END)
profile
신입 모바일 개발자 입니다!

0개의 댓글