우분투 실전 명령어 | systemctl 서비스 제어 핵심
우분투 실전 명령어 | systemctl 서비스 제어 핵심
언제 쓰는가
서비스가 안 뜨거나, 설정 변경 후 반영이 안 될 때 가장 많이 쓰는 명령어가 systemctl입니다. 서비스 생명주기(시작/중지/재시작/자동시작)를 정확히 이해하면 장애 대응 속도가 크게 빨라집니다.
바로 쓰는 명령어
서비스 시작/중지/상태:
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl status nginx재시작/설정 리로드:
sudo systemctl restart nginx
sudo systemctl reload nginx부팅 시 자동 시작 설정:
sudo systemctl enable nginx
sudo systemctl disable nginx목록 확인:
systemctl list-units --type service --all
systemctl list-unit-files --type service핵심 포인트
restart는 중지 후 시작,reload는 중단 없이 설정 반영- 서비스명은
nginx처럼 줄여도 되지만, 경우에 따라nginx.service가 필요 - 설정 파일 변경 후에는
daemon-reload가 필요할 수 있음
자주 하는 실수
- 설정 바꿔놓고
daemon-reload를 빼먹음 reload로 반영되지 않는 서비스에 계속 reload만 시도- status 확인 없이 start/restart만 반복
검증 방법
systemctl status nginx --no-pager
sudo systemctl daemon-reload실행 결과 예시
systemctl status nginx --no-pager 정상 예시:
● nginx.service - A high performance web server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled)
Active: active (running)systemctl enable nginx 실행 시 예시:
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /lib/systemd/system/nginx.service.운영 팁
장애 대응 시에는 status와 journalctl -u <service>를 함께 보면 원인 파악 속도가 크게 올라갑니다.