Search

[Systemctl] 리눅스 시작시 서비스 등록, 생성, 삭제

1. 서비스 생성

기본 서비스 등록 장소 : /usr/lib/systemd/system
서비스 스크립트 생성
vim /usr/lib/systemd/[SERVICE_NAME].service
Bash
복사
[Unit] Description="My Description" Requires=local-fs.target After=local-fs.target [Service] Type=simple ExecStart=/path/to/service.sh ExecStop=/bin/kill -15 $MAINPID [Install] WantedBy=multi-user.target
Bash
복사

2. 서비스 등록

서비스 등록 (심볼릭 링크 생성)
# Register a service sudo ln -s /home/root/custom-service/[SERVICE_NAME].service /etc/systemd/system/ ls -l /etc/systemd/system/[SERVICE_NAME].service # check # Create a service sudo systemctl enable [SERVICE_NAME].service # activate service sudo systemctl start [SERVICE_NAME].service # start service sudo systemctl status [SERVICE_NAME].service # check status # Restart a service sudo systemctl restart [SERVICE_NAME].service
Bash
복사

1. 서비스 삭제하기

서비스 비활성화
sudo systemctl stop [SERVICE_NAME] sudo systemctl disable [SERVICE_NAME]
Bash
복사
서비스 삭제 (심볼릭 링크 삭제)
# Remove a service rm /etc/systemd/system/[SERVICE_NAME] rm /etc/systemd/system/[SERVICE_NAME] # and symlinks that might be related rm /usr/lib/systemd/system/[SERVICE_NAME] rm /usr/lib/systemd/system/[SERVICE_NAME] # and symlinks that might be related # Restart a systemctl deamon systemctl daemon-reload systemctl reset-failed
Shell
복사