J.BF Story
[Ubuntu] 서비스 등록 (systemd) 본문
Ubuntu 18.04
1. 서비스 파일 생성
/etc/systemd/system/test.service
[Unit]
Description=Test Service
After=multi-user.target
[Service]
Type=simple
User=testuser
Group=testuser
WorkingDirectory=/home/testuser/program
ExecStart=/home/testuser/anaconda3/bin/python run.py
Restart=on-failure
[Install]
WantedBy=multi-user.target
- User, Group / WorkingDirectory
- [옵션] 프로그램 실행 유저 / 프로그램 작업 디렉터리
- ExecStart 앞에 위치해야 설정이 적용됨
- Restart=on-failure: 서비스 종료 시 자동 재시작
- 필요 시 'Environment'로 환경변수를 설정할 수 있음
2. 서비스 등록
systemctl daemon-reload
# 서버 재부팅 시에 서비스 자동 시작
systemctl enable test.service
# 서비스 시작
systemctl start test.service
3. 서비스 확인
systemctl status test.service
** 에러 메세지 확인
journalctl -xe -u test.service
'Server > Linux' 카테고리의 다른 글
[Linux] Symbolic link 생성 / 삭제 (0) | 2022.07.28 |
---|---|
[Ubuntu] Jupyter Notebook 서비스 생성(systemd) (0) | 2022.07.26 |
[Linux] vi 에디터 .swp 파일 경고 해결(Swap file already exist) (0) | 2022.07.23 |
[SSH 원격 접속] WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED 오류 (0) | 2022.06.27 |
[Centos] 서버 정보 확인 명령어 모음 (0) | 2022.06.18 |
Comments