본문 바로가기
Linux/Tips&News

systemctl vs service

by 드로니뚜벅이 2023. 4. 25.

가끔씩 프로그램을 설치하거나 설정을 변경할 경우 프로그램을 재시작해야 하는 경우가 있습니다. 이럴 때 service 명령어를 사용할지 아니면 systemctl 명령어를 사용할지 헷갈리곤 합니다. 물론 둘 중 어느 것을 사용하더라도 같습니다만...

 

service

init.d에서 서비스 관리 시 사용하는 명령으로 이전 리눅스 배포 버젼에서 사용하는 명령어이며 최근 리눅스 배포판에서 service 명령을 사용할 경우 systemctl로 전달되어 처리됩니다.

 

systemctl

최근 리눅스 배포 버전에서 서비스 유닛(서비스이름.service)을 관리 하는데 사용하는 명령어로 /usr/lib/systemd  또는 /lib/systemd/system 디렉토리 아래에 확장자가 .service인 파일을 만들면, systemctl 명령을 통해 서비스를 제어할 수 있습니다.
service 파일은 크게 Unit, Service, Install 3가지의 섹션으로 구성됩니다.

  1 # postgresql.service is the meta unit for managing all PostgreSQL clusters on                        
  2 # the system at once. Conceptually, this unit is more like a systemd target,
  3 # but we are using a service since targets cannot be reloaded.
  4 #
  5 # The unit actually managing PostgreSQL clusters is postgresql@.service,
  6 # instantiated as postgresql@15-main.service for individual clusters.
  7 
  8 [Unit]
  9 Description=PostgreSQL RDBMS
 10 
 11 [Service]
 12 Type=oneshot
 13 ExecStart=/bin/true
 14 ExecReload=/bin/true
 15 RemainAfterExit=on
 16 
 17 [Install]
 18 WantedBy=multi-user.target