[Unit]\r\nDescription=Apache Tomcat\r\nAfter=network.target\r\n\r\n[Service]\r\nType=forking\r\n\r\nUser=tomcat\r\nGroup=tomcat\r\n\r\nEnvironment=JAVA_HOME=\/usr\/lib\/jvm\/java-11-openjdk-amd64\r\nEnvironment=CATALINA_PID=\/opt\/tomcat\/tomcat.pid\r\nEnvironment=CATALINA_HOME=\/opt\/tomcat\r\nEnvironment=CATALINA_BASE=\/opt\/tomcat\r\nEnvironment=\"CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC\"\r\n\r\nExecStart=\/opt\/tomcat\/bin\/startup.sh\r\nExecStop=\/opt\/tomcat\/bin\/shutdown.sh\r\n\r\nExecReload=\/bin\/kill $MAINPID\r\nRemainAfterExit=yes\r\n\r\n[Install]\r\nWantedBy=multi-user.target<\/pre>\nSave the file and exit.<\/p>\n
Run the following command to reload the systemd manager configuration:<\/p>\n
# systemctl daemon-reload<\/pre>\nTo run Tomcat now and make the service run upon reboot, we can run this command:<\/p>\n
# systemctl enable --now tomcat<\/pre>\nWe can check and verify Tomcat service by running this command:<\/p>\n
# systemctl status tomcat<\/pre>\nIt will show you an output like this:<\/p>\n
root@ubuntu22:~# systemctl status tomcat\r\n\u25cf tomcat.service - Apache Tomcat\r\nLoaded: loaded (\/etc\/systemd\/system\/tomcat.service; enabled; vendor preset: enabled)\r\nActive: active (running) since Mon 2022-05-09 11:34:31 UTC; 1s ago\r\nProcess: 29526 ExecStart=\/opt\/tomcat\/bin\/startup.sh (code=exited, status=0\/SUCCESS)\r\nMain PID: 29533 (java)\r\nTasks: 15 (limit: 4697)\r\nMemory: 85.4M\r\nCPU: 3.575s\r\nCGroup: \/system.slice\/tomcat.service\r\n\u2514\u250029533 \/usr\/lib\/jvm\/java-11-openjdk-amd64\/bin\/java -Djava.util.logging.config.file=\/opt\/tomcat\/conf\/logging.properties -Djava.util.logging.manager=org.>\r\n\r\nMay 09 11:34:31 ubuntu22.rosehosting.com systemd[1]: Starting Apache Tomcat...\r\nMay 09 11:34:31 ubuntu22.rosehosting.com startup.sh[29526]: Tomcat started.\r\nMay 09 11:34:31 ubuntu22.rosehosting.com systemd[1]: Started Apache Tomcat.<\/pre>\n<\/p>\n
As you can see, Tomcat is now running and listening on its default port 8080. You can open your web browser and navigate to http:\/\/YOUR_SERVER_IP_ADDRESS:8080<\/p>\n
<\/p>\n