본문 바로가기

리눅스/Ubuntu

[우분투 부팅시 서비스 자동 시작]

[우분투 부팅시 서비스 자동 시작]

cd /etc/systemd/system 
위 경로에서 vi를 이용해 서비스 생성

ex)
sudo vi /etc/systemd/system/lprapi.service


vi 진입하면 아래 내용 복사 (크게 3가지로 나뉨 Unit / Service / install] 

 [Unit]
 Description= 서비스 설명
 After= 해당 유닛이 시작된 이후 나열된 유닛이 실행

 [Service]
 Type=idle
 WorkingDirectory= 스크립트(파일명.sh) 파일의 경로  /usr/local/src/smlpr 
 ExecStart=/usr/local/src/smlpr/smlpr_deploy.sh (스크립트 파일의 절대경로와 실행파일 이름까지 포함)
 StandardOutput=로그파일을 생성할 위치와 로그파일 이름 (usr/local/src/smlpr/API.log)
 StandardError= 에러파일을 생성할 위치와 에러파일 이름/usr/local/src/smlpr/API_error.log

 [Install]
 WantedBy= "systemctl enable" 명령어로 유닛을 등록할때 등록에 필요한 유닛을 지정 (고정)


[출처]
https://khann.tistory.com/5 [khann's IT와 경제 블로그]
https://naknaklee.github.io/etc/2020/07/19/linux-auto-start/