Table of Contents
systemctl is the main tool for managing services on modern Linux servers. It allows you to control services, check their status, and debug failures without rebooting the VPS.
Step 1: Check Service Status
Before restarting or stopping a service, always check its current state.
sudo systemctl status nginx
Replace nginx with the service name you want to inspect.
Step 2: Restart a Service
Restarting reloads the service and applies configuration changes.
sudo systemctl restart nginx
Use this after editing config files.
Step 3: Stop a Service
Stopping a service fully terminates it.
sudo systemctl stop nginx
The service will remain stopped until started manually.
Step 4: Start a Service
Start a stopped service.
sudo systemctl start nginx
Step 5: Enable or Disable Services at Boot
Control whether a service starts automatically after reboot.
sudo systemctl enable nginx
sudo systemctl disable nginx
Step 6: Debug a Failed Service
If a service fails, systemctl shows the exit reason.
sudo systemctl status nginx
Look for lines marked as failed or error.
Step 7: View Detailed Service Logs
Use journalctl to inspect service logs.
sudo journalctl -u nginx
Show recent logs only:
sudo journalctl -u nginx --since "10 minutes ago"
You may also want to review this related article:
Optional Step: Reload a Service Without Restart
Reload applies configuration changes without dropping connections.
sudo systemctl reload nginx