This content originally appeared on DEV Community and was authored by Ahmad Zia
As a DevOps engineer, automation and service management are critical. While working with Java-based web applications, Apache Tomcat is one of the most widely used tools to serve Java servlets and JSPs. However, starting and stopping Tomcat manually using shell scripts (startup.sh
and shutdown.sh
) isn’t ideal in a production environment.
In this guide, we’ll walk through setting up Tomcat as a systemd service, allowing us to manage it easily using systemctl
— just like any other system service!
✅ What is Tomcat?
Apache Tomcat is an open-source application server developed by the Apache Software Foundation. It's used to host Java-based web applications, similar to how Apache HTTPD serves websites.
🛠️ Setup Steps
1. Install Required Software
First, install Tomcat and Java:
sudo yum install java-17-openjdk -y
Download and extract Tomcat from the official website. You’ll typically extract it using:
tar -xvzf apache-tomcat-9.x.xx.tar.gz
2. Start Tomcat Manually (Initial Test)
To make sure everything works initially, run:
cd apache-tomcat-9.x.xx/bin./startup.sh
Then, open your browser and visit:
http://<your_server_ip>:8080
You should see the Tomcat welcome page.
❌ The Problem
By default, Tomcat requires manual start/stop using shell scripts. That’s not ideal for production or automation. We need to integrate it into our system’s service manager – systemd
.
✅ The DevOps Solution: Use systemctl
We’ll create a custom systemd service file for Tomcat, enabling us to manage it using:
sudo systemctl start tomcat
sudo systemctl stop tomcat
sudo systemctl enable tomcat
🧰 Step-by-Step Guide
🔹 Step 1: Create a Non-root Tomcat User
It’s a security best practice to run services as non-root users.
sudo useradd -m -U -d /opt/tomcat -s /bin/false tomcat
🔹 Step 2: Move Tomcat Files
Assuming you’ve already extracted Tomcat:
sudo mv apache-tomcat-9.x.xx /opt/tomcat
sudo chown -R tomcat: /opt/tomcat
🔹 Step 3: Create systemd Service File
Create a new file:
sudo nano /etc/systemd/system/tomcat.service
Paste the following configuration:
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target
[Service]
User=tomcat
Group=tomcat
Environment=JAVA_HOME=/usr/lib/jvm/jre
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
WorkingDirectory=/opt/tomcat
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
🔎 Note: Replace JAVA_HOME with the actual path of your installed JDK, if different.
🔹 Step 4: Reload systemd and Start Tomcat
sudo systemctl daemon-reload
sudo systemctl start tomcat
To make Tomcat start automatically at boot:
sudo systemctl enable tomcat
To check the status:
sudo systemctl status tomcat
🎯 Final Test
Visit your server IP on port 8080 again:
http://<your_server_ip>:8080
If you see the Tomcat page — congratulations! You’ve successfully integrated Tomcat into your Linux service system.
This content originally appeared on DEV Community and was authored by Ahmad Zia

Ahmad Zia | Sciencx (2025-07-13T03:39:39+00:00) Managing Apache Tomcat with systemd on Linux – A DevOps Guide. Retrieved from https://www.scien.cx/2025/07/13/managing-apache-tomcat-with-systemd-on-linux-a-devops-guide/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.