What are the ways to start Tomcat in Linux?
There are multiple ways to start Tomcat on Linux, here are some commonly used methods:
- To start Tomcat using the startup script: go to the bin directory of Tomcat and run the command ./startup.sh. To stop Tomcat, run the command ./shutdown.sh.
- To use systemd: create a file called tomcat.service in the directory /etc/systemd/system and add the following content:
[Unit]
Description=Tomcat
After=syslog.target network.target
[Service]
User=tomcat
Group=tomcat
Type=forking
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
To start Tomcat, execute the following command.
sudo systemctl start tomcat
To stop Tomcat, run the following command:
sudo systemctl stop tomcat
- Create a file named ‘tomcat’ in the /etc/init.d/ directory and add the following content to it using an init.d script.
#!/bin/sh
# description: Tomcat Start Stop Restart
# processname: tomcat
# chkconfig: 234 20 80
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
CATALINA_HOME=/usr/local/tomcat
export CATALINA_HOME
case $1 in
start)
sh $CATALINA_HOME/bin/startup.sh
;;
stop)
sh $CATALINA_HOME/bin/shutdown.sh
;;
restart)
sh $CATALINA_HOME/bin/shutdown.sh
sh $CATALINA_HOME/bin/startup.sh
;;
esac
exit 0
Then, execute the following command to start Tomcat:
sudo service tomcat start
To stop Tomcat, run the following command:
sudo service tomcat stop
These are several commonly used methods, choose the appropriate one according to your own needs to start Tomcat.