Managing Services

The systemctl command is your primary tool for managing systemd services. The key distinction between operations is runtime state (is it running right now?) versus boot configuration (will it start at next boot?). Conflating these two is the most common source of confusion: starting a service does not enable it, and enabling a service does not start it.

Start, stop, restart

# Start a service (runtime only — does not persist across reboots)
sudo systemctl start nginx

# Stop a service
sudo systemctl stop nginx

# Restart a service (stop then start)
sudo systemctl restart nginx

# Conditionally restart (only if service is currently running)
sudo systemctl try-restart nginx    # No-op if stopped

# Check the effect immediately
sudo systemctl status nginx

Reload vs restart

# Reload: send SIGHUP to the process (re-reads config without stopping)
# Use when: nginx config change, sshd config change, etc.
sudo systemctl reload nginx

# Restart: stop the process and start it again
# Use when: binary was updated, major config change, reload not supported

# Try reload, fall back to restart if reload not supported
sudo systemctl reload-or-restart nginx

# Check if a service supports reload
systemctl show nginx.service -p CanReload

Output

CanReload=yes

💡 TIP: For production web servers, prefer reload over restart when only the configuration changed. A reload applies the new config without dropping existing connections. A restart drops all active connections, causing brief downtime.

Enable and disable

# Enable: create symlinks so service starts at boot
sudo systemctl enable nginx
# Output: Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service

# Enable AND start right now (common pattern)
sudo systemctl enable --now nginx

# Disable: remove symlinks so service does NOT start at boot
sudo systemctl disable nginx

# Disable AND stop right now
sudo systemctl disable --now nginx

# Check if enabled
systemctl is-enabled nginx

is-enabled output values

enabled       — Will start at boot (symlink exists)
disabled      — Will NOT start at boot
static        — Cannot be enabled (started by dependency only)
masked        — Completely disabled, cannot be started manually either
generated     — Dynamically generated unit (fstab entries, etc.)

Masking a service

# Mask: strongest disable — symlink to /dev/null, cannot be started at all
sudo systemctl mask nginx
# Useful when: you want to ensure a service NEVER runs (e.g., removing Apache
# to prevent accidental start when nginx is your web server)

# Unmask: re-enable the ability to start it
sudo systemctl unmask nginx

# Try to start a masked service (shows error)
sudo systemctl start nginx
# Failed to start nginx.service: Unit nginx.service is masked.

⚠️ WARNING: Masking is drastic. If you mask a service that is a dependency for other services, those services may fail to start. Always check systemctl list-dependencies --reverse servicename to see what depends on the service before masking it.

Checking service status

# Full status with recent log lines
sudo systemctl status nginx

systemctl status output explained

● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2026-06-09 14:30:05 UTC; 2h 15min ago
#            ↑                 ↑                              ↑
#        current state     start time                     uptime
    Main PID: 1234 (nginx)
       Tasks: 3 (limit: 4678)
      Memory: 8.5M
         CPU: 45ms
      CGroup: /system.slice/nginx.service
              ├─1234 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
              └─1235 "nginx: worker process"

Jun 09 14:30:05 server nginx[1234]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Jun 09 14:30:05 server nginx[1234]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Jun 09 14:30:05 server systemd[1]: Started A high performance web server and a reverse proxy server.
# One-line status checks (useful in scripts)
systemctl is-active nginx    # Outputs: active or inactive
systemctl is-enabled nginx   # Outputs: enabled or disabled
systemctl is-failed nginx    # Outputs: failed or active

# Check status and use exit code in scripts
if systemctl is-active --quiet nginx; then
    echo "nginx is running"
fi

Conclusion

The two most important distinctions in service management: start/stop affects only runtime, while enable/disable affects boot configuration. Always use enable --now when deploying a new service so it both starts immediately and persists across reboots. Use reload instead of restart for production services when only the config changed. Use systemctl status as your first diagnostic step — it shows the last few log lines, current process tree, memory usage, and whether the service is correctly configured to start at boot.

FAQ

Is Managing Services important for Ubuntu administrators?+

Yes. It supports practical Ubuntu administration because it connects directly to server reliability, security, troubleshooting, or daily operations.

Should I practice this on a live server?+

Use a lab VM first. After you understand the command output and rollback path, apply the workflow carefully on real systems.

What should I do after reading this article?+

Run the practice commands, write down what each one shows, and continue to the next article in the Ubuntu roadmap.

Need help with Ubuntu administration?

Work directly with Muhammad Irfan Aslam for Ubuntu Server, Linux, cloud, Docker, DevOps, CI/CD, or infrastructure troubleshooting support.

Hire Me for Support