File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ # Create systemd service file for Tomcat with JDK 17
4+ cat << EOF > /etc/systemd/system/tomcat.service
5+ [Unit]
6+ Description=Apache Tomcat Web Application Container
7+ After=network.target
8+
9+ [Service]
10+ Type=forking
11+
12+ User=ubuntu
13+ Group=ubuntu
14+
15+ Environment=JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
16+ Environment=CATALINA_PID=/opt/tomcat9/temp/tomcat.pid
17+ Environment=CATALINA_HOME=/opt/tomcat9
18+ Environment=CATALINA_BASE=/opt/tomcat9
19+ Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
20+
21+ ExecStart=/bin/sh /opt/tomcat9/bin/startup.sh
22+ ExecStop=/bin/sh /opt/tomcat9/bin/shutdown.sh
23+
24+ Restart=on-failure
25+
26+ [Install]
27+ WantedBy=multi-user.target
28+ EOF
29+
30+ # Ensure ubuntu owns the Tomcat directory
31+ chown -R ubuntu:ubuntu /opt/tomcat9
32+
33+ # Optional: Make WAR files executable (not typically required)
34+ chmod +x /opt/tomcat9/webapps/* .war
35+
36+ # Reload systemd to register the new service
37+ systemctl daemon-reload
38+
39+ # Enable and start the Tomcat service
40+ systemctl enable tomcat
41+ systemctl start tomcat
You can’t perform that action at this time.
0 commit comments