systemd Basics: Starting, Stopping and Enabling Linux Services
Most Linux servers rely on background services.
These might include:
- web servers
- databases
- SSH
- printing
- Docker
- networking
- monitoring tools
On most modern Linux distributions, those services are managed by systemd.
The main command you use to control them is:
systemctl
The commands themselves are simple.
What matters is understanding the difference between:
running now
and:
starting automatically later.
The Six Commands You Need First
For a service called nginx:
sudo systemctl start nginx
Starts it now.
sudo systemctl stop nginx
Stops it now.
sudo systemctl restart nginx
Stops and starts it again.
sudo systemctl enable nginx
Configures it to start automatically through its normal systemd dependencies, usually during boot.
sudo systemctl disable nginx
Removes that automatic-start configuration.
systemctl status nginx
Shows what state it is currently in.
These cover most everyday service administration.
Start and Enable Are Not the Same Thing
This is the single most important systemd concept.
If you run:
sudo systemctl start nginx
Nginx starts immediately.
But that does not necessarily mean it will start after the next reboot.
If you run:
sudo systemctl enable nginx
systemd configures it for future automatic activation.
But that does not normally start it immediately.
Your current article already explains this distinction correctly.
To do both in one command:
sudo systemctl enable --now nginx
This means:
enable it for later + start it now.
Disabling Does Not Stop a Running Service
The same rule works in reverse.
If you run:
sudo systemctl disable nginx
Nginx may continue running until:
- you stop it
- the machine reboots
- something else changes its state
To disable and stop it immediately:
sudo systemctl disable --now nginx
This is a very useful shortcut.
Check Whether a Service Is Running
For a detailed view:
systemctl status nginx
Typical information includes:
- Loaded state
- enabled/disabled state
- Active state
- Main PID
- recent logs
For a simple yes/no-style check:
systemctl is-active nginx
Possible results include:
active
inactive
failed
activating
Your live article correctly distinguishes runtime state from enablement state.
Check Whether It Starts Automatically
Run:
systemctl is-enabled nginx
You may see:
enabled
disabled
static
masked
These do not all mean the same thing.
enabled
Configured for automatic activation.
disabled
Not enabled directly, but it can still be started manually or by another unit.
static
Usually cannot be enabled directly because it has no installation section.
It may still be started as a dependency.
masked
Explicitly blocked from being started.
This is stronger than disabled.
Restart vs Reload
These are also different.
Restart
sudo systemctl restart nginx
Stops the service and starts it again.
That can briefly interrupt the service.
Reload
sudo systemctl reload nginx
Asks the service to reread its configuration without fully stopping.
Not every service supports reload.
You can check:
systemctl show nginx -p CanReload
If you see:
CanReload=yes
the service declares reload support.
For production systems, reload can be preferable because it may avoid interruption.
Validate Configuration Before Restarting
This is especially important on remote servers.
Before restarting something critical, test its configuration where possible.
For Nginx:
sudo nginx -t
For OpenSSH:
sudo sshd -t
For Apache on many systems:
sudo apachectl configtest
Only restart after the configuration test succeeds.
This matters particularly for:
- SSH
- networking
- firewalls
- web servers
- databases
A typo in an SSH configuration file followed by an immediate restart can lock you out of the server.
Your existing article includes this warning and it is worth keeping prominently.
Viewing Service Logs
When a service fails, systemctl status is a good first check.
Then use the journal.
For one service:
journalctl -u nginx
Recent entries:
journalctl -u nginx -n 50
Current boot only:
journalctl -u nginx -b
Follow new log messages live:
journalctl -u nginx -f
For more detailed troubleshooting:
journalctl -xeu nginx
The important point is:
Do not repeatedly restart a failed service without reading why it failed.
“Failed” Does Not Mean systemd Is Broken
Suppose:
systemctl status nginx
shows:
failed
Possible causes include:
- invalid configuration
- missing file
- permissions problem
- port already in use
- failed dependency
- incorrect credentials
- missing mounted storage
- application crashing immediately
Check:
journalctl -xeu nginx
Fix the underlying problem.
Then start it again.
If necessary, clear the recorded failure state:
sudo systemctl reset-failed nginx
Then:
sudo systemctl start nginx
reset-failed does not repair the service.
It only clears systemd's remembered failed state and related counters. Your current article gets this distinction right.
“Start Request Repeated Too Quickly”
You may see:
Start request repeated too quickly
That usually means:
- service starts
- service crashes
- systemd retries
- service crashes again
- retries happen too quickly
- systemd stops retrying
Do not just keep running:
sudo systemctl restart service-name
Instead inspect:
systemctl status service-name
and:
journalctl -u service-name -b
Find out why the application is crashing.
Why Does a Disabled Service Still Start?
This surprises many people.
A service can be:
disabled
and still run because another systemd unit activates it.
For example:
- socket unit
- timer
- dependency
- device event
- another service
Check dependencies:
systemctl list-dependencies service-name
Reverse dependencies:
systemctl list-dependencies --reverse service-name
Look for related units:
systemctl list-unit-files | grep service-name
You may discover:
example.service
example.socket
example.timer
Disabling the .service alone may therefore not stop every activation path.
Masking a Service
If you need to prevent a unit from being started at all:
sudo systemctl mask service-name
To stop it at the same time:
sudo systemctl mask --now service-name
Undo it with:
sudo systemctl unmask service-name
Masking is much stronger than disabling.
Use it carefully.
Do not casually mask core components such as:
- networking
- storage
- authentication
- security services
on a remote or production system.
List Running Services
To see loaded service units:
systemctl list-units --type=service
Running services only:
systemctl list-units --type=service --state=running
Failed services:
systemctl --failed
This is particularly useful after:
- a reboot
- failed update
- server outage
- configuration change
Service Names Can Differ Between Distributions
Do not assume the unit has the same name everywhere.
Examples:
OpenSSH
Debian/Ubuntu commonly:
ssh.service
Fedora/RHEL commonly:
sshd.service
Apache
Debian/Ubuntu:
apache2.service
Fedora/RHEL:
httpd.service
If unsure:
systemctl list-unit-files --type=service | grep ssh
or:
systemctl list-unit-files --type=service | grep apache
Your live article correctly calls this out because it prevents a lot of unnecessary confusion.
What Is a Unit?
systemd manages objects called units.
Services are only one type.
Common examples include:
.service
.socket
.timer
.target
.mount
.automount
.path
.device
.swap
For everyday application management, you will mostly work with:
.service
But understanding that systemd manages more than conventional background processes explains why services can be activated by sockets, timers, dependencies and other events.
Do You Need to Type .service?
Usually not.
These are generally equivalent:
sudo systemctl restart ssh
and:
sudo systemctl restart ssh.service
For interactive use, omitting .service is convenient.
For scripts and technical documentation, using the full unit name can sometimes be clearer.
View the Actual Unit Definition
If you need to understand how a service is configured:
systemctl cat nginx
This can show:
- vendor unit file
- administrator overrides
- drop-ins
That is safer than guessing which file under /usr/lib, /lib or /etc/systemd/system contains the definition.
To see the main unit-file path:
systemctl show nginx -p FragmentPath
Editing a Service Safely
Avoid editing vendor-provided unit files directly if you can.
Package upgrades may overwrite them.
For an administrator override:
sudo systemctl edit nginx
systemd creates a drop-in configuration under /etc/systemd/system.
For example:
[Service]
Restart=on-failure
After changing systemd unit definitions:
sudo systemctl daemon-reload
Then restart the affected service if necessary.
Important:
daemon-reload
does not restart your services.
It tells systemd to reread unit definitions.
daemon-reload vs reload
These sound similar but do different things.
systemctl daemon-reload
Reloads systemd's own unit-file configuration.
Use after changing:
.service.timer- drop-in configuration
- other unit definitions
systemctl reload nginx
Asks Nginx itself to reread its application configuration.
That distinction is worth remembering:
daemon-reload = systemd configuration
reload = application configuration
A Safe Service-Change Workflow
For an important Linux service:
- Check current status:
systemctl status service-name
- Back up important configuration.
- Edit the configuration.
- Run the application's validation command if available.
- If you changed a systemd unit:
sudo systemctl daemon-reload
- Reload where supported:
sudo systemctl reload service-name
or restart if necessary:
sudo systemctl restart service-name
- Confirm:
systemctl is-active service-name
- Review logs:
journalctl -u service-name -n 50
That is much safer than:
edit → restart → hope.
The Essential systemd Cheat Sheet
| Goal | Command |
|---|---|
| Start now | sudo systemctl start service |
| Stop now | sudo systemctl stop service |
| Restart | sudo systemctl restart service |
| Reload configuration | sudo systemctl reload service |
| Start automatically | sudo systemctl enable service |
| Stop automatic enablement | sudo systemctl disable service |
| Enable + start now | sudo systemctl enable --now service |
| Disable + stop now | sudo systemctl disable --now service |
| Check runtime state | systemctl is-active service |
| Check enablement | systemctl is-enabled service |
| Detailed status | systemctl status service |
| View logs | journalctl -u service |
| Show failed units | systemctl --failed |
| Block activation | sudo systemctl mask service |
| Allow activation again | sudo systemctl unmask service |
| Reread unit files | sudo systemctl daemon-reload |
How Hamilton Group Can Help
systemd makes Linux service management consistent, but problems become more complicated when they involve:
- dependencies
- service crashes
- permissions
- mounts
- network availability
- custom unit files
- security policies
- production systems
Hamilton Group can help with:
- Linux server support
- systemd
- service troubleshooting
- server monitoring
- web servers
- Docker
- networking
- automation
- managed IT support
For production systems, the goal is not simply to know how to type:
systemctl restart
It is to understand why the service stopped, whether restarting it is safe, and how to stop the problem happening again.
Visit hgmssp.com or call 01423 438 953.
0 comments
- Be the first to comment.