Before vs After: When Your Service Won’t Behave
Before: you install something on your server, try to run it, and get nothing. Your website is down, your app won’t start, and every guide says “just use systemctl” like it’s obvious.
After: you know exactly how to start, stop, restart, and auto-start services using systemd. You can check what’s active and keep your services under control instead of guessing.
This guide is for anyone running a Linux server with systemd (most modern distros) who just wants to manage services without reading a 300‑page manual.
We’ll use the nginx.service unit as an example (like in the source). You’ll need Nginx installed from your package manager if you want to follow along exactly.
Step 1: Understand What a “Unit” and “Service” Are
systemd works with objects called “units”. A unit is just something systemd knows how to manage.
There are different types of units, but the most common type you’ll touch is a service, which has a file ending in .service (for example: nginx.service).
To manage these units, you use one main tool: systemctl.
So when you see commands like:
sudo systemctl start nginx.servicesudo systemctl stop nginx.service
…that’s you telling systemd what to do with a specific service unit.
If you’re running commands on a production server, make sure you:
- Use
sudo(or root) so systemd actually accepts what you’re asking. - Know which service you’re touching. Stopping the wrong one can take your site down.
Step 2: Start, Stop, Restart, and Reload a Service
This is the bread and butter of systemd usage: controlling a single service.
We’ll use nginx.service as the sample unit, but you can swap it for any other service name on your box.
Start a service
If Nginx is installed but not running yet:
sudo systemctl start nginx.service
That tells systemd: “start this service now”.
Use this when:
- You just installed a service and want to run it.
- You stopped it earlier and now need it back online.
Stop a service
To stop Nginx:
sudo systemctl stop nginx.service
This immediately stops the service.
Be careful with this on production: your websites or apps using that service will go offline until you start it again.
Restart a service
If you changed a config file or the service is acting weird, restarting is the usual move:
sudo systemctl restart nginx.service
This is basically a stop + start in one step.
Use restart when:
- You updated the service.
- You changed config and want to apply it.
- The service is half‑broken and needs a clean run.
Reload a service (softer than restart)
Sometimes you just want the service to reload its config without fully stopping.
For that, try reload:
sudo systemctl reload nginx.service
This tells the service: “reload your settings if you can, but try not to interrupt normal work”.
Not every service supports reload properly, but when it does, it’s usually less disruptive than a full restart.
Step 3: Enable or Disable Services at Boot
By default, most systemd unit files do not start automatically when the server boots.
If you reboot and your app or web server doesn’t come back up, this is usually the reason.
systemd handles this using enable and disable.
When you enable a service, you hook it into a specific boot “target” (a state systemd reaches during boot). Once hooked, systemd will start that service when the system hits that target.
Enable a service (start on boot)
To make Nginx start automatically on every boot:
sudo systemctl enable nginx.service
This changes the systemd configuration so that when your system reaches the right boot target, nginx.service is started.
Use enable when:
- You want your web or app server to survive reboots without manual starts.
- You’re done testing and ready for it to run like a normal service.
Disable a service (don’t start on boot)
To turn off auto‑start behavior:
sudo systemctl disable nginx.service
This doesn’t stop the service right now. It only means that after the next reboot, systemd won’t automatically start it.
Use disable when:
- You’re testing or debugging and don’t want it auto‑starting.
- You’ve replaced a service with something else.
- You want to prevent something from coming up after maintenance or a server restart.
Quick note to avoid confusion:
stopaffects the current running state.disableaffects future boots.
If you want a service off now and off on boot, run both:
sudo systemctl stop nginx.service
sudo systemctl disable nginx.service
Step 4: Get an Overview of Active Units
Sometimes you log in and your first question is: “What’s actually running right now?”
systemd can show you an overview of the units it considers active.
To see all the unit files systemd has listed as active:
systemctl list-units
In fact, list-units is the default behavior of systemctl, so you can also just run:
systemctl
This gives you a quick overview of what systemd thinks is up and running.
Use this when:
- You’re not sure if a service is started.
- You want to see generally what systemd is managing at the moment.
Step 5: Practical Usage Patterns on a Real Server
Let’s put the pieces together into some common workflows you’ll hit when managing a box.
New service just installed, make sure it runs and survives reboot
- Start it now:
bash
sudo systemctl start nginx.service
- Enable it for future boots:
bash
sudo systemctl enable nginx.service
This combo is what you want whenever you install something that should always be on.
Service misbehaving after config changes
- Try a reload first (less disruptive):
bash
sudo systemctl reload nginx.service
- If that doesn’t fix it, go for a restart:
bash
sudo systemctl restart nginx.service
Reload when possible, restart when needed.
Temporarily stop a service without touching boot settings
If you just want to stop it for now, but don’t want to change its auto‑start behavior:
sudo systemctl stop nginx.service
When the server reboots, it will behave according to whether it’s enabled or disabled, not because of this stop.
Fully retire or pause a service
If you want it off now and also off after reboot:
sudo systemctl stop nginx.service
sudo systemctl disable nginx.service
That way you don’t get surprises after maintenance or a reboot window.
Step 6: Basic Safety Habits When Using systemctl
A few simple habits go a long way toward avoiding outages when you’re poking around with systemd.
1. Double‑check the service name
Typos can either do nothing or hit the wrong service if you autocomplete incorrectly.
If in doubt, list units first:
systemctl list-units
Look for the exact name (for example, nginx.service) before running stop or restart.
2. Know the environment you’re on
On a production machine, stopping nginx.service or another core service will almost always mean downtime.
If you can, test commands on a staging or test server first, using the same service name.
3. Use sudo where needed
Most of these commands require root privileges.
If you’re not using sudo (or not root), the command might fail silently or just tell you it can’t do what you asked.
Stick to the sudo systemctl ... pattern unless you’ve configured something special.
4. Restart vs reload: pick the right tool
- Try
reloadfirst when you change configuration. - Use
restartwhen: - Reload is not supported, or
- The service is already unhappy.
Reload is often gentler on active connections, while restart is a clean break.
Step 7: Quick Reference Cheat Sheet
Here’s a compact view you can mentally keep for day‑to‑day work:
- Start now:
bash
sudo systemctl start nginx.service
- Stop now:
bash
sudo systemctl stop nginx.service
- Restart now:
bash
sudo systemctl restart nginx.service
- Reload config (if supported):
bash
sudo systemctl reload nginx.service
- Enable on boot:
bash
sudo systemctl enable nginx.service
- Disable on boot:
bash
sudo systemctl disable nginx.service
- List active units:
bash
systemctl list-units
Get used to that set, and you’ll feel a lot less scared of systemd.
Wrap Up
You don’t need to understand every internal detail of systemd to manage a Linux server safely.
If you can start, stop, restart, reload, enable, disable, and list units with systemctl, you’ve already covered the most important daily tasks.
Use these commands carefully, especially on production, and you’ll keep your services behaving with far less drama.
Need more help? Check the latest CrushEdge posts.
No Comments