Ubuntu 20.04.6 LTS

 

1. 서비스 파일 만들기 

/etc/systemd/system 디렉토리에 파일을 만든다.

 

vi myservice.service

[Unit]
Description=서비스 설명 
Wants=network.target
After=network.target

[Service]
Type=simple
WorkingDirectory=작업디렉토리 /home/ubuntu/myservice
Environment="PATH=/home/ubuntu/.nvm/versions/node/v16.10.0/bin:$PATH"
ExecStart=/opt/conda/envs/pytorch/bin/uvicorn main:app --reload --host=0.0.0.0 --port=8000
Restart=on-failure
RestartSec=3s
StandardOutput=file:/var/log/myservice/log.log
StandardError=file:/var/log/myservice/log.log

[Install]
WantedBy=multi-user.target

 

2. 서비스 등록 및 실행

* 서비스 데몬 재실행

systemctl daemon-reload

 

* 서비스활성화

systemctl enable myservice.service

 

* 서비스 시작

systemctl start myservice.service

 

* 서비스 상태 확인

systemctl status myservice.service

 

3. 트러블슈팅

로그 파일 경로의 디렉토리가 없다면 만들어준다.

 

 

참고 https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html

'내 시간을 뺐는 참사들 > System' 카테고리의 다른 글

dockerfile nvm nodejs 설치 방법  (0) 2023.04.26

+ Recent posts