본문 바로가기
리눅스

[리눅스] Linux Service .service 파일

by 꾸준하곰 2022. 6. 8.

Linux Service

Service 에 등록하면, 리눅스가 재부팅 됐을 때 자동으로 start 해준다. 

또한, stop, restart 등 애플리케이션을 관리할 수 있다.

 

1. Service 파일 만들기 (.service)

2. Service 파일 등록

3. Service 관련 명령어


1. Service 파일 만들기 (.service)

[Unit]
Description=Start Server
After=해당 서비스의 시작된 이후 나열된 서비스를 실행

[Service]
ExecStart=경로
WorkingDirectory=프로세스의 작업 디렉토리
Restart=서비스가 죽었거나 응답이 없을 때 재시작 옵션

[Install]
WantedBy=서비스 등록할 때 필요한 서비스

 

2. Service 파일 등록

root 권한으로 systemd (system demon) 을 관리하는 systemctl 명령어를 사용한다.

sudo chmod 755 /etc/systemd/system/my.service	#실행권한 부여
sudo systemctl daemon-reload		#systemctl 데몬 재 실행
sudo systemctl enable my.service	#서비스 자동실행 등록(enable)
sudo systemctl start my.service		#서비스 시작
sudo systemctl status my.service	#서비스 상태 확인

 

3. Service 관련 명령어

systemctl 설명
systemctl start 파일명 서비스 시작
systemctl stop 파일명 서비스 중지
systemctl restart 파일명 서비스 재시작
systemctl reload 파일명 서비스 설정 재구동
systemctl status 파일명 서비스 상태 확인

 

댓글