Subject: Configure Tomcat to survive instance reboot
Author: Linux
In response to: Manually download and unpack the Tomcat package
Posted on: 10/22/2017 09:52:14 PM
First, create a systemd service file tomcat.service
$ sudo nano /etc/systemd/system/tomcat.service
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/local/java/jdk1.8.0_152/jre
Environment=CATALINA_PID=/opt/tomcat/apache-tomcat-8.5.23/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat/apache-tomcat-8.5.23
Environment=CATALINA_BASE=/opt/tomcat/apache-tomcat-8.5.23
Environment='CATALINA_OPTS=-Xms128M -Xmx512M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'
ExecStart=/opt/tomcat/apache-tomcat-8.5.23/bin/startup.sh
ExecStop=/opt/tomcat/apache-tomcat-8.5.23/bin/shutdown.sh
User=administrator
Group=administrator
UMask=0007
RestartSec=10
Restart=always
[Install]
WantedBy=multi-user.target
Then, enable the service (it will auto-start after reboot):
$ sudo systemctl daemon-reload
$ sudo systemctl enable tomcat
If you want to start the service right now (in this session), type the command
$ sudo systemctl start tomcat
OR
$ sudo systemctl restart tomcat
You can check the status of a given service by
$ sudo systemctl status tomcat
tomcat.service - Apache Tomcat Web Application Container
Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: e
Active: active (running) since Sun 2017-10-22 14:40:10 PDT; 13min ago
Process: 950 ExecStart=/opt/tomcat/apache-tomcat-8.5.23/bin/startup.sh (code=e
Main PID: 996 (java)
CGroup: /system.slice/tomcat.service
└─996 /usr/local/java/jdk1.8.0_152/jre/bin/java -Djava.util.logging.c
Oct 22 14:40:09 ubuntu systemd[1]: Starting Apache Tomcat Web Application Contai
Oct 22 14:40:10 ubuntu startup.sh[950]: Existing PID file found during start.
Oct 22 14:40:10 ubuntu startup.sh[950]: Removing/clearing stale PID file.
Oct 22 14:40:10 ubuntu startup.sh[950]: Tomcat started.
Oct 22 14:40:10 ubuntu systemd[1]: Started Apache Tomcat Web Application Contain
>
> On 10/21/2017 01:30:30 AM
Linux wrote:
Step 1) Download the Tomcat package
First go to http://tomcat.apache.org/download-80.cgi, find the tar.gz under Binary Distributions and download it to local Windows machine.
Step 2). Make the folder available
$ sudo mkdir /opt/tomcat
$ cd /opt
$ sudo chmod 777 tomcat
Step 3). Upload the downloaded Tomcat by WinSCP
Copy apache-tomcat-8.5.23.tar.gz onto /opt/tomcat
Step 4). Unzip the package
$ cd /opt/tomcat
$ tar xzf apache-tomcat-8.5.23.tar.gz
The Tomcat content is under folder /opt/tomcat/apache-tomcat-8.5.23
Step 5). Verify it is working
$ cd /opt/tomcat/apache-tomcat-8.5.23
$ ./bin/startup.sh
Using CATALINA_BASE: /opt/tomcat/apache-tomcat-8.5.23
Using CATALINA_HOME: /opt/tomcat/apache-tomcat-8.5.23
Using CATALINA_TMPDIR: /opt/tomcat/apache-tomcat-8.5.23/temp
Using JRE_HOME: /usr/local/java/jdk1.8.0_152
Using CLASSPATH: /opt/tomcat/apache-tomcat-8.5.23/bin/bootstrap.jar:/opt/
tomcat/apache-tomcat-8.5.23/bin/tomcat-juli.jar
Tomcat started.
Goto the box's browser and use localhost
Or other machine's browser and use box's ip-address
Finally, stop it
References: