Engineering/WEB & WAS

[Tomcat] 톰캣 서비스 등록

[앙금빵] 2021. 11. 22.

톰캣 서비스 등록

#1 /usr/lib/systemd/system 디렉토리에 톰캣 서비스 등록
vim /usr/lib/systemd/system/tomcat.service

---
[Unit] 
Description=tomcat 8.5
After=network.target syslog.target

[Service]
Type=forking

# 환경변수 설정 시 할 필요 없음
# Environment="톰캣 경로"

User=root
Group=root

#ExecStart=톰캣 경로/bin/startup.sh
ExecStart=/usr/local/tomcat8.5/bin/startup.sh

# ExecStop=톰캣 경로/bin/shutdown.sh
ExecStop=/usr/local/tomcat8.5/bin/shutdown.sh

# 디렉토리 권한 770 && 새로운 파일 권한 660
UMask=0007

[Install]
WantedBy=multi-user.target
---

 

서비스 등록

# 서비스 설정을 데몬에 즉시 반영
[root@localhost system]# systemctl daemon-reload

# 시작서비스 등록
[root@localhost system]# systemctl enable /usr/lib/systemd/system/tomcat.service

Created symlink from /etc/systemd/system/multi-user.target.wants/tomcat.service to /usr/lib/systemd/system/tomcat.service.

 

테스트

[root@localhost system]# systemctl start tomcat
[root@localhost system]# systemctl status tomcat

● tomcat.service - tomcat 8.5
   Loaded: loaded (/usr/lib/systemd/system/tomcat.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2021-08-22 16:28:20 UTC; 2s ago
  Process: 579 ExecStart=/usr/local/tomcat8.5/bin/startup.sh (code=exited, status=0/SUCCESS)
 Main PID: 593 (java)
   CGroup: /system.slice/tomcat.service
           └─593 /usr/bin/java -Djava.util.logging.config.file=/usr/local/tomcat8.5/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls....

Aug 22 16:28:20 ip-10-0-0-158.ap-northeast-2.compute.internal systemd[1]: Starting tomcat 8.5...
Aug 22 16:28:20 ip-10-0-0-158.ap-northeast-2.compute.internal startup.sh[579]: Tomcat started.
Aug 22 16:28:20 ip-10-0-0-158.ap-northeast-2.compute.internal systemd[1]: Started tomcat 8.5.

# 부팅시 자동실행
[root@localhost system]# systemctl enable tomcat

 

참조

https://opensrc.tistory.com/200

https://hoing.io/archives/178?hilite=tomcat

댓글