How to Manage Services with systemctl on Linux
Control Linux services with systemctl — start, stop, restart, enable at boot, and check status with clear examples for Nginx, SSH, and more.
What Is systemctl?
On modern Linux systems (Ubuntu 16+, Debian 8+, RHEL/CentOS 7+), systemd manages services. The systemctl command is how you interact with it. Whether you're managing a web server, a database, or a custom application, the commands are always the same.
Core Service Commands
sudo systemctl start nginx # start a service
sudo systemctl stop nginx # stop a service
sudo systemctl restart nginx # stop then start
sudo systemctl reload nginx # reload config without full restart
sudo systemctl status nginx # show current status and recent logs
Enable and Disable at Boot
Starting a service with systemctl start only runs it until the next reboot. To make it permanent:
sudo systemctl enable nginx # start automatically on boot
sudo systemctl disable nginx # stop starting automatically
sudo systemctl enable --now nginx # enable AND start immediately
Reading the Status Output
sudo systemctl status ssh
The output tells you:
- Active: active (running) — service is up
- Active: failed — service crashed or failed to start
- Loaded: enabled — will start on boot
- The last few log lines from the service journal
Checking All Services
systemctl list-units --type=service # all active services
systemctl list-units --type=service --state=failed # failed services only
systemctl list-unit-files --type=service # all installed services + enabled state
Common Services to Know
sshorsshd— SSH servernginx— Nginx web serverapache2orhttpd— Apache web servermysqlormariadb— MySQL/MariaDB databasepostgresql— PostgreSQL databaseufw— UFW firewall servicecron— cron job scheduler
Debugging a Failed Service
# Check status for clues
sudo systemctl status myapp
# Read the full journal log for the service
sudo journalctl -u myapp -n 100 --no-pager
# Try starting it manually to see errors in real time
sudo systemctl start myapp
sudo journalctl -u myapp -f
Creating a Simple Custom Service
Save a file to /etc/systemd/system/myapp.service:
[Unit]
Description=My Node App
After=network.target
[Service]
User=www-data
WorkingDirectory=/var/www/myapp
ExecStart=/usr/bin/node server.js
Restart=always
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now myapp