⚙️OS/Linux

[Linux] Cent OS 7에서 서비스 등록하기

뉴발자 2024. 5. 23.
728x90

 

 

 

 

 

 

 

 

 

 

 

 

 

그림 1. Linux

 

 

서비스 파일 생성

경로

/etc/systemd/system

 

파일 생성

sudo vi [서비스명].service

 

파일 내용

[Unit]
Description=Test Service Start
After=syslog.target network.target postgresql.service

[Service]
ExecStart=/usr/lib/jdk-17.0.10/bin/java -jar /usr/server/test.jar
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target

 

섹션 옵션 설명
Unit Description  서비스에 대한 설명
  Before  서비스가 시작되기 전 실행할 명령어
  After  서비스가 시작된 후 실행할 명령어
Service ExecStart  서비스 시작 시 실행되는 명령어
  Restart  서비스 재시작 조건 ( no | on-success | on-failure | on-watchdog | on-abort | always )
 (옵션에 대한 자세한 설명은 아래 사이트 참조) 
  RestartSec  서비스를 재시작하기 전 절전 시간
 기본 값은 100ms
Install WantedBy  systemctl enable 명령어로 유닛을 등록할 때 등록에 필요한 유닛을 지정

 

 

서비스 등록 및 실행

서비스 데몬에 반영

systemctl daemon-reload

 

등록된 서비스 목록 확인

systemctl -t service list-unit-files

 

서비스 실행

systemctl start [서비스명]

 

서비스 상태 확인

systemctl status [서비스명]

 

재부팅 시 서비스 자동 실행

systemctl enable [서비스명]

 

 

참고 사이트

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

 

systemd.service

Sometimes, units should just execute an action without keeping active processes, such as a filesystem check or a cleanup action on boot. For this, Type=oneshot exists. Units of this type will wait until the process specified terminates and then fall back t

www.freedesktop.org

 

https://fmd1225.tistory.com/93

 

systemd unit 등록 관련 옵션 정리

- RHEL 7 의 OS 적인 가장 큰 변화는 3.x 커널을 사용한다는 점(물론 2.6.x 커널에서 큰 차이가 있는 것은 아니다.) 그리고 정통적인 init 데몬에서 systemd 데몬으로 변경이 되었다는 점이다. systemd 에 대

fmd1225.tistory.com

 

 

 

 

 

 

 

 

 

 

728x90

댓글