If you want to start Tomcat automatically when system boots up, you need to configure it as a system service.
Let’s create a new file tomcat11.service in /etc/systemd/system
[Unit] Description=Apache Tomcat11 After=network.target [Service] Type=forking Environment="JAVA_HOME=/home/tomcat/jdk-21.0.1" Environment="CATALINA_PID=/home/tomcat/apache-tomcat-11.0.0-M14/temp/tomcat.pid" Environment="CATALINA_HOME=/home/tomcat/apache-tomcat-11.0.0-M14" Environment="CATALINA_BASE=/home/tomcat/apache-tomcat-11.0.0-M14" Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseG1GC" Environment="JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom" ExecStart=/home/tomcat/apache-tomcat-11.0.0-M14/bin/startup.sh ExecStop=/home/tomcat/apache-tomcat-11.0.0-M14/bin/shutdown.sh User=tomcat Group=tomcat UMask=0007 RestartSec=10 Restart=always [Install] WantedBy=multi-user.target
you need to set your own environment JAVA_HOME, CATALINA_HOME, CATALINA_BASE, CATALINA_PID and ExecStart, ExecStop parameters.
After saving tomcat11.service file, we need to reload systemd daemon with
sudo systemctl daemon-reload
Now starting tomcat service..
sudo systemctl start tomcat11.service
Verify service status
sudo systemctl status tomcat11.service
Stop tomcat service.
sudo systemctl stop tomcat11.service
Now we can enable the Tomcat service to run on startup.
sudo systemctl enable tomcat11.service
Ok, that’s it!