Operations 8 min read

Master systemd: From Basics to Managing Nginx, Tomcat, and Java Services

This article introduces systemd as the modern Linux service manager, explains its key features and unit file syntax, and provides step‑by‑step practical examples for controlling Nginx, Tomcat, and custom Java JAR applications with systemd commands.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master systemd: From Basics to Managing Nginx, Tomcat, and Java Services

systemd Introduction

systemd is the primary system daemon manager on modern Linux, replacing init because init handles processes serially and only runs startup scripts, leading to blocking and limited service management. Since CentOS 7, systemd is the default.

systemd Features

Adopted by latest systems (RedHat7, CentOS7, Ubuntu15…)

Parallel service start on boot improves boot speed

Shutdown only stops running services, unlike CentOS6 which stops all

Service start/stop no longer uses scripts under /etc/init.d

Resolves issues such as lingering child processes after service stop

systemd Syntax

systemctl [command] [unit]

Common commands:

start      systemctl start nginx
stop       systemctl stop nginx
restart    systemctl restart nginx
reload     systemctl reload nginx
enable     systemctl enable nginx
disable    systemctl disable nginx
status     systemctl status nginx

systemd Unit Files

Each unit requires a configuration file.

Files are stored in /usr/lib/systemd/system/ with symlinks in /etc/systemd/system/ after enabling.

Service files use the .service suffix.

System units reside in /usr/lib/systemd/system/, user units in .../user/.

Configuration sections are case‑sensitive and enclosed in brackets.

Practical Example 1: Manage Nginx with systemd

Compile and install nginx, then create /usr/lib/systemd/system/nginx.service:

[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

Control with systemctl start|stop|restart|enable nginx.

Practical Example 2: Manage Tomcat with systemd

Install JDK, extract Tomcat, then create /usr/lib/systemd/system/tomcat.service:

[Unit]
Description=tomcat server
Wants=network-online.target
After=network.target

[Service]
Type=forking
Environment="JAVA_HOME=/usr/java/jdk1.8.0_231-amd64"
Environment="PATH=$JAVA_HOME/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin"
Environment="CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar"
ExecStart=/usr/local/tomcat/bin/startup.sh
ExecStop=/usr/local/tomcat/bin/shutdown.sh
Restart=on-failure

[Install]
WantedBy=multi-user.target

Use systemctl start|stop|restart|enable tomcat.

Practical Example 3: Manage a Java JAR Service

Create a bash script (demo.sh) that starts and stops the JAR, then define a unit file /usr/lib/systemd/system/abc.service:

[Unit]
Description=uams server
Wants=network-online.target
After=network.target

[Service]
Type=forking
WorkingDirectory=/usr/local/abc/
ExecStart=/bin/bash uams.sh start
ExecStop=/bin/bash uams.sh stop
ExecReload=/bin/bash uams.sh restart
Restart=on-failure

[Install]
WantedBy=multi-user.target

Control with systemctl restart abc, systemctl enable abc, systemctl stop abc, and systemctl status abc.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

NGINXSystem AdministrationService Managementsystemd
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.