Quick Answer:
systemctl start nginxstarts a service.systemctl stop nginxstops it.systemctl restart nginxrestarts.systemctl enable nginxmakes it start on boot.systemctl status nginxshows if it's running and recent logs.
Essential Commands
# Start a service
sudo systemctl start nginx
# Stop a service
sudo systemctl stop nginx
# Restart (stop + start)
sudo systemctl restart nginx
# Reload config without stopping (if supported)
sudo systemctl reload nginx
# Check status
systemctl status nginx
# Enable (start on boot)
sudo systemctl enable nginx
# Disable (don't start on boot)
sudo systemctl disable nginx
# Enable AND start immediately
sudo systemctl enable --now nginx
# Check if running
systemctl is-active nginx
# Check if enabled on boot
systemctl is-enabled nginx
Check Service Status
systemctl status nginx
Output explained:
● nginx.service - A high performance web server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2026-04-06 10:00:00 CDT; 2h ago
Docs: man:nginx(8)
Process: 1234 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Main PID: 1235 (nginx)
Tasks: 5 (limit: 4915)
Memory: 12.5M
CPU: 234ms
CGroup: /system.slice/nginx.service
├─1235 "nginx: master process /usr/sbin/nginx"
└─1236 "nginx: worker process"
Apr 06 10:00:00 server systemd[1]: Starting A high performance web server...
Apr 06 10:00:00 server systemd[1]: Started A high performance web server.
| Field | Meaning |
|---|---|
active (running) |
Service is running normally |
inactive (dead) |
Service is stopped |
failed |
Service crashed or failed to start |
enabled |
Will start on boot |
disabled |
Will not start on boot |
List Services
# All running services
systemctl list-units --type=service --state=running
# All services (including stopped)
systemctl list-units --type=service
# All failed services
systemctl --failed
# All enabled services (start on boot)
systemctl list-unit-files --type=service --state=enabled
Common Services
| Service | What it is |
|---|---|
nginx |
Web server |
apache2 |
Web server (Debian) / httpd (CentOS) |
mysql |
MySQL database |
postgresql |
PostgreSQL database |
docker |
Docker daemon |
ssh or sshd |
SSH server |
ufw |
Firewall |
fail2ban |
Intrusion prevention |
cron |
Task scheduler |
redis-server |
Redis cache |
mongod |
MongoDB |
# Examples
sudo systemctl restart mysql
sudo systemctl status docker
sudo systemctl enable --now fail2ban
sudo systemctl reload nginx
View Service Logs
# Recent logs for a service
journalctl -u nginx -n 50
# Follow logs (live)
journalctl -u nginx -f
# Logs since last hour
journalctl -u nginx --since "1 hour ago"
# Errors only
journalctl -u nginx -p err
# Logs from current boot
journalctl -u nginx -b
Create Your Own Service
If you have a Node.js app, Python script, or any program you want to run as a service:
Create /etc/systemd/system/myapp.service:
[Unit]
Description=My Application
After=network.target
[Service]
Type=simple
User=www-data
WorkingDirectory=/opt/myapp
ExecStart=/usr/bin/node /opt/myapp/server.js
Restart=on-failure
RestartSec=5
Environment=NODE_ENV=production
Environment=PORT=3000
[Install]
WantedBy=multi-user.target
Then:
sudo systemctl daemon-reload
sudo systemctl enable --now myapp
sudo systemctl status myapp
Troubleshooting
Service Won't Start
# Check what went wrong
systemctl status myapp
journalctl -u myapp -n 30 --no-pager
# Common causes:
# - Wrong ExecStart path
# - Permission denied (wrong User)
# - Port already in use
# - Missing dependencies
Service Keeps Crashing
# Check how many times it restarted
systemctl show myapp -p NRestarts
# Check exit code
systemctl show myapp -p ExecMainStatus
# View the crash logs
journalctl -u myapp --since "10 minutes ago"
Reset a Failed Service
# Clear the failed state
sudo systemctl reset-failed myapp
# Then start it
sudo systemctl start myapp
Reload After Editing Service File
# After editing any .service file
sudo systemctl daemon-reload
sudo systemctl restart myapp