Service

SpringBoot - 내장 Tocmat systemctl 등록

dalgong 2025. 1. 22. 14:11
반응형

1. 서비스 등록 파일 설정

  • vim /etc/systemd/system/tomcat.service
[Unit]
Description=Service Description
After=syslog.target network.target postgresql.service

[Service]
Environment=PATH=/usr/local/jdk-21/bin
ExecStart=/bin/bash -c "exec java -jar /data/gradle/gradle-8.11.1/app/build/libs/tomcat.jar"
Restart=on-failure
RestartSec=10

User=root
Group=root

[Install]
WantedBy=multi-user.target

2. 서비스 실행

root@ip-10-100-0-182:/etc/systemd/system# systemctl daemon-reload

root@ip-10-100-0-182:~# systemctl start tomcat.service 

root@ip-10-100-0-182:~# systemctl status tomcat.service 
● tomcat.service - Service Description
     Loaded: loaded (/etc/systemd/system/tomcat.service; disabled; preset: enabled)
     Active: active (running) since Mon 2024-12-30 00:44:26 UTC; 4s ago
   Main PID: 1886 (java)
      Tasks: 34 (limit: 9507)
     Memory: 177.5M (peak: 193.5M)
        CPU: 6.686s
     CGroup: /system.slice/tomcat.service
             └─1886 java -jar /data/gradle/gradle-8.11.1/app/build/libs/app.jar

Dec 30 00:44:29 ip-10-100-0-182 bash[1886]: 2024-12-30T00:44:29.507Z  INFO 1886 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
Dec 30 00:44:29 ip-10-100-0-182 bash[1886]: 2024-12-30T00:44:29.508Z  INFO 1886 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.30]
Dec 30 00:44:29 ip-10-100-0-182 bash[1886]: 2024-12-30T00:44:29.634Z  INFO 1886 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
Dec 30 00:44:29 ip-10-100-0-182 bash[1886]: 2024-12-30T00:44:29.636Z  INFO 1886 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1648 ms
Dec 30 00:44:30 ip-10-100-0-182 bash[1886]: 2024-12-30T00:44:30.105Z  INFO 1886 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
Dec 30 00:44:30 ip-10-100-0-182 bash[1886]: 2024-12-30T00:44:30.155Z  INFO 1886 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 2.949 seconds (process running for 3.709)
Dec 30 00:44:31 ip-10-100-0-182 bash[1886]: 2024-12-30T00:44:31.009Z  INFO 1886 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
Dec 30 00:44:31 ip-10-100-0-182 bash[1886]: 2024-12-30T00:44:31.010Z  INFO 1886 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
Dec 30 00:44:31 ip-10-100-0-182 bash[1886]: 2024-12-30T00:44:31.011Z  INFO 1886 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 1 ms
Dec 30 00:44:31 ip-10-100-0-182 bash[1886]: 2024-12-30T00:44:31.049Z  INFO 1886 --- [nio-8080-exec-1] com.example.demo.HelloController         : Returning response: Hello, World!
반응형