Ubuntu 서비스 관리: 조회, 추가, 수정, 삭제
등록일: 2026. 4. 1.
Ubuntu Systemd 서비스 관리 가이드
이 문서는 우분투(Ubuntu)에서 systemd를 이용해 서비스를 조회, 추가, 수정, 삭제하는 방법을 다룹니다.
1. 서비스 조회 (List)
현재 시스템에 등록된 서비스들의 상태를 확인합니다.
- 전체 서비스 목록 (활성/비활성 포함):
systemctl list-units --type=service - 현재 실행 중인 서비스만 보기:
systemctl list-units --type=service --state=running - 부팅 시 자동 실행 설정 상태 확인:
systemctl list-unit-files --type=service
2. 서비스 추가 (Add)
새로운 서비스를 등록하려면 /etc/systemd/system/ 디렉토리에 .service 파일을 생성해야 합니다.
서비스 파일 생성
sudo nano /etc/systemd/system/nexus-raid.service
서비스 파일 내용 예시
[Unit]
Description=Nexus Raid Module Service
After=network.target
[Service]
User=sleepzz
# 작업 디렉토리
WorkingDirectory=/sorc001/nexus/raid
# 실행 명령어
# -Dserver.port=8009 : 포트 강제 지정
# -Dspring.profiles.active=prod : 프로필 지정
ExecStart=/usr/bin/java -jar -Dserver.port=8009 -Dspring.profiles.active=prod /sorc001/nexus/raid/raid.jar
SuccessExitStatus=143
Restart=on-failure
RestartSec=5
# 로그 경로 (/logs001/nexus/workout)
StandardOutput=append:/logs001/nexus/raid/output.log
StandardError=append:/logs001/nexus/raid/error.log
[Install]
WantedBy=multi-user.target
3. 서비스 적용 및 관리 (Apply)
파일을 생성하거나 수정한 후에는 시스템에 이를 알려야 합니다.
- 설정 파일 리로드 (필수):
sudo systemctl daemon-reload - 서비스 시작:
sudo systemctl start nexus-raid.service - 부팅 시 자동 실행 등록:
sudo systemctl enable nexus-raid.service - 서비스 상태 확인:
systemctl status nexus-raid.service
4. 서비스 수정 (Modify)
- 파일 수정:
sudo nano /etc/systemd/system/nexus-raid.service - 변경사항 반영:
sudo systemctl daemon-reload - 서비스 재시작:
sudo systemctl restart nexus-raid.service
5. 서비스 삭제 (Delete)
서비스를 완전히 제거하는 절차입니다.
- 서비스 중지:
sudo systemctl stop nexus-raid.service - 자동 실행 해제:
sudo systemctl disable nexus-raid.service - 서비스 파일 삭제:
sudo rm /etc/systemd/system/nexus-raid.service - 시스템 초기화:
sudo systemctl daemon-reload
sudo systemctl reset-failed
6. 주요 명령어 요약
| 기능 | 명령어 |
|---|---|
| 시작 / 중지 | systemctl start / stop |
| 재시작 | systemctl restart |
| 상태 확인 | systemctl status |
| 로그 확인 | journalctl -u 서비스명 -f |