[CentOS] Linux Service 등록하는 방법
2020. 12. 2. 16:06
728x90
반응형
CentOS 7부터는 이전에 사용하던 SysV(init system) 대신하여, systemd 을 system & service manager 로 사용합니다.
systemctl는 systemd 를 컨트롤하는 cli 명령어입니다.
1. Service 등록
[root@ ] #cd /etc/systemd/system/multi-user.target.wants
먼저 위의 경로로 이동해 줍니다.
CentOS6 까지는 /etc/rc.d/init.d 디렉토리에 서비스 관련 파일들이 있었습니다.
CentOS7부터는 서비스들이 대부분 Unit으로 분리되었고, 이 Unit들은 [서비스이름].service 파일명으로 생성하며, systemctl 명령어로 제어하도록 변경되었습니다.
아래와 같이 testserver.service 이름의 파일을 생성해 줍니다.
[root@ ] #vi testserver.service
[Unit]
Description=Test Server
After=network.target
[Service]
ExecStart=/usr/share/dotnet/dotnet /opt/test-server/TestServer/TestServer.dll
WorkingDirectory=/opt/test-server/TestServer
KillSignal=SIGINT
SyslogIdentifier=testserver
[Install]
WantedBy=multi-user.target
WorkingDirectory 가 다를 경우, 각 프로그램에서 제아하는 폴더의 경로 때문에, 파일 생성 및 읽기가 비정상적으로 동작할 수 있습니다.
dotnet 으로 구성한 서버였는데, BaseDirectory를 가져오는 부분이 WorkingDirectory 로 인해 잘못 Load 하는 경우가 있었습니다.
2. 서비스 시작
[root@ ] #systemctl stop testserver.service
[root@ ] #systemctl start testserver.service
[root@ ] #systemctl enable testserver.service
[root@ ] #systemctl disable testserver.service
등록을 마쳤다면, 위와 같이 systemctl 명령어를 이용해서 service를 제어할 수 있습니다.
출처
728x90
'OS > Linux' 카테고리의 다른 글
[Linux] 리눅스 종류 및 버전 확인하는 방법 - CentOS, Ubuntu (1) | 2023.12.11 |
---|---|
[CentOS] CentOS 7 - Redis 설치 위치 및 버전 확인 (0) | 2021.11.01 |
[CentOS 7] CentOS 7 FTP 설치 및 설정하기 (0) | 2020.03.06 |
[CentOS 7] CentOS 7 - NGINX 설치 방법 (4) | 2020.03.02 |
[CentOS 7] 방화벽 해제하기 - firewall-cmd (0) | 2020.02.25 |