Restarting Services from the Command Line in Linux: A Complete Administrator’s Guide
Managing Linux services efficiently is one of the most fundamental skills any system administrator must master. Whether you're applying configuration changes, recovering from an unexpected crash, troubleshooting a misbehaving daemon, or simply refreshing a running process, knowing how to restart services from the command line is essential for keeping your infrastructure healthy and responsive.
This comprehensive guide walks you through every major method for restarting Linux services — covering systemd, SysVinit, and Upstart — along with practical examples, status-checking techniques, log analysis tips, and best practices that experienced administrators rely on daily.
Understanding Linux Services and Service Managers
In Linux, a service (also called a daemon) is a background process that performs a specific, ongoing function. Common examples include:
- Apache / Nginx — web server daemons
- MySQL / PostgreSQL — database server daemons
- SSH (sshd) — secure shell access daemon
- Cron — scheduled task daemon
- Postfix / Dovecot — mail server daemons
These services are controlled by an init system or service manager, which is responsible for starting, stopping, restarting, and monitoring them. The three most common service managers you'll encounter on Linux are:
| Service Manager | Used In |
|---|---|
| systemd | Ubuntu 15.04+, Debian 8+, CentOS 7+, RHEL 7+, Fedora, AlmaLinux, Rocky Linux |
| SysVinit | Older Debian, older Ubuntu (pre-15.04), legacy RHEL/CentOS 6 |
| Upstart | Ubuntu 9.10 through 14.10 |
The vast majority of modern Linux servers — including those running on VPS Hosting or Dedicated Servers — use systemd as their default service manager. However, understanding all three systems ensures you're prepared for any environment you encounter.
Method 1: Restarting Services with systemd (Modern Linux)
systemd is the dominant init system on virtually all modern Linux distributions. It manages services through the systemctl command-line utility, which provides a consistent, powerful interface for service management.
Step 1: Open a Terminal
Access your server's command line interface — either directly, via SSH, or through your hosting control panel.
Step 2: Restart a Service
The basic syntax for restarting a service with systemd is:
sudo systemctl restart <service-name>Common real-world examples:
# Restart the Apache web server
sudo systemctl restart apache2
# Restart Nginx
sudo systemctl restart nginx
# Restart MySQL / MariaDB
sudo systemctl restart mysql
# Restart the SSH daemon
sudo systemctl restart sshd
# Restart the Cron scheduler
sudo systemctl restart cron
# Restart Postfix mail server
sudo systemctl restart postfix> Note: On some distributions, the service name may differ slightly. For example, Apache may be apache2 on Debian/Ubuntu systems but httpd on CentOS/RHEL/AlmaLinux systems.
Step 3: Verify the Service Restarted Successfully
After issuing a restart command, always confirm the service came back up cleanly:
sudo systemctl status <service-name>Example output for a healthy Apache service:
sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2025-01-13 10:45:22 UTC; 3s ago
Process: 12345 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 12346 (apache2)The key indicators to look for:
Active: active (running)— the service is running normallyActive: failed— the service failed to start; check logs immediatelyLoaded: enabled— the service is configured to start automatically at boot
Additional Useful systemd Commands
Beyond a simple restart, systemd provides several related commands that administrators use regularly:
# Stop a service completely
sudo systemctl stop <service-name>
# Start a stopped service
sudo systemctl start <service-name>
# Reload configuration without a full restart (if supported)
sudo systemctl reload <service-name>
# Reload config or restart if reload isn't supported
sudo systemctl reload-or-restart <service-name>
# Enable a service to start automatically at boot
sudo systemctl enable <service-name>
# Disable a service from starting at boot
sudo systemctl disable <service-name>
# Check if a service is currently active
sudo systemctl is-active <service-name>
# Check if a service is enabled at boot
sudo systemctl is-enabled <service-name>Viewing Real-Time Service Logs with journalctl
systemd integrates with the journal logging system. To view logs for a specific service:
# View all logs for a service
sudo journalctl -u apache2
# Follow logs in real time (like tail -f)
sudo journalctl -u apache2 -f
# View only the most recent 50 lines
sudo journalctl -u apache2 -n 50
# View logs since the last boot
sudo journalctl -u apache2 -bThis is invaluable when a service fails to restart and you need to diagnose the root cause quickly.
Method 2: Restarting Services with SysVinit (Legacy Linux)
SysVinit is an older init system still found on legacy servers, embedded systems, and older Linux distributions. If you're maintaining an older server environment, you'll use the service command to manage daemons.
Step 1: Open a Terminal
Connect to your server via SSH or direct console access.
Step 2: Restart a Service
sudo service <service-name> restartCommon examples:
# Restart MySQL
sudo service mysql restart
# Restart Apache
sudo service apache2 restart
# Restart Nginx
sudo service nginx restart
# Restart the SSH daemon
sudo service ssh restart
# Restart Postfix
sudo service postfix restartStep 3: Check Service Status
sudo service <service-name> statusExample:
sudo service mysql status
● mysql.service - MySQL Community Server
Active: active (running) since Mon 2025-01-13 10:47:00 UTC; 5s agoOther SysVinit Service Commands
# Stop a service
sudo service <service-name> stop
# Start a service
sudo service <service-name> start
# Reload configuration
sudo service <service-name> reloadYou can also interact with SysVinit services directly using the init scripts located in /etc/init.d/:
sudo /etc/init.d/apache2 restart
sudo /etc/init.d/mysql status> Compatibility Note: On modern systemd-based distributions, the service command still works as a compatibility wrapper — it automatically translates service commands into systemctl calls behind the scenes. This means you can safely use service commands on modern systems, though systemctl is preferred for its additional features.
Method 3: Restarting Services with Upstart (Ubuntu Legacy)
Upstart was Ubuntu's init system from version 9.10 through 14.10, before systemd replaced it in Ubuntu 15.04. If you're maintaining a very old Ubuntu server, you'll use the initctl command.
Step 1: Open a Terminal
Step 2: Restart a Service
sudo initctl restart <service-name>Examples:
# Restart lighttpd
sudo initctl restart lighttpd
# Restart MySQL
sudo initctl restart mysqlStep 3: Check Service Status
sudo initctl status <service-name>Example:
sudo initctl status lighttpd
lighttpd start/running, process 4521Other Upstart Commands
# Stop a service
sudo initctl stop <service-name>
# Start a service
sudo initctl start <service-name>
# List all Upstart-managed jobs and their states
sudo initctl listHow to Identify Which Service Manager Your System Uses
If you're connecting to an unfamiliar server and aren't sure which init system is in use, run these quick diagnostic commands:
# Check if systemd is running as PID 1
ps -p 1 -o comm=
# Or check the init system directly
cat /proc/1/comm
# Check systemd version (if installed)
systemctl --version
# Check if Upstart is present
initctl --version
# Check for SysVinit scripts
ls /etc/init.d/If ps -p 1 -o comm= returns systemd, you're on a systemd system. If it returns init, you're likely on SysVinit or Upstart.
Best Practices for Restarting Linux Services
Experienced administrators follow a set of best practices to minimize downtime and avoid configuration errors when restarting services:
1. Always Validate Configuration Before Restarting
Many services provide a built-in syntax check. Use it before restarting to avoid bringing a service down with a broken config:
# Test Apache configuration
sudo apachectl configtest
# or
sudo apache2ctl -t
# Test Nginx configuration
sudo nginx -t
# Test SSH daemon configuration
sudo sshd -t
# Test MySQL configuration
sudo mysqld --validate-configIf the configuration test passes, proceed with the restart. If it fails, fix the errors first.
2. Use reload Instead of restart When Possible
A reload applies configuration changes without interrupting active connections, making it far less disruptive than a full restart:
# Gracefully reload Apache (zero downtime)
sudo systemctl reload apache2
# Gracefully reload Nginx
sudo systemctl reload nginxUse restart only when a full process restart is genuinely required (e.g., after a software update or when reload isn't supported).
3. Check Logs Immediately After a Failed Restart
If a service fails to come back up, check the logs without delay:
# systemd journal (most detailed)
sudo journalctl -u <service-name> -n 100 --no-pager
# Application-specific log files
sudo tail -n 50 /var/log/apache2/error.log
sudo tail -n 50 /var/log/nginx/error.log
sudo tail -n 50 /var/log/mysql/error.log
sudo tail -n 50 /var/log/syslog4. Be Careful When Restarting SSH on Remote Servers
If you're connected to a remote server via SSH and restart the SSH daemon, you risk losing your connection. Mitigate this risk:
# Safer: reload SSH config without dropping connections
sudo systemctl reload sshd
# If you must restart, use a delayed command to give yourself time to reconnect
sudo shutdown -r +1 # schedules a reboot in 1 minute (use only if necessary)5. Understand the Impact on Running Processes
Restarting a database service like MySQL or PostgreSQL will terminate all active database connections. Always notify application teams or schedule maintenance windows for production systems before restarting critical services.
6. Ensure Services Are Enabled to Restart After Reboot
After restarting a service manually, verify it's set to start automatically after a system reboot:
sudo systemctl enable <service-name>Quick Reference: Service Management Commands Cheat Sheet
| Action | systemd | SysVinit | Upstart |
|---|---|---|---|
| Restart | systemctl restart <svc> | service <svc> restart | initctl restart <svc> |
| Start | systemctl start <svc> | service <svc> start | initctl start <svc> |
| Stop | systemctl stop <svc> | service <svc> stop | initctl stop <svc> |
| Reload | systemctl reload <svc> | service <svc> reload | initctl reload <svc> |
| Status | systemctl status <svc> | service <svc> status | initctl status <svc> |
| Enable at boot | systemctl enable <svc> | update-rc.d <svc> enable | N/A |
| View logs | journalctl -u <svc> | /var/log/syslog | /var/log/upstart/<svc>.log |
Troubleshooting Common Service Restart Issues
Service Fails to Start After Restart
Symptoms: systemctl status shows Active: failed
Steps to diagnose:
# Get detailed failure reason
sudo systemctl status <service-name>
sudo journalctl -u <service-name> -n 50
# Check for port conflicts
sudo ss -tlnp | grep <port-number>
sudo netstat -tlnp | grep <port-number>
# Check file permissions on config files
ls -la /etc/<service-config-file>Service Restarts But Doesn't Apply New Configuration
Cause: Configuration file has a syntax error, or the wrong config file is being loaded.
Solution:
# Verify which config file the service is using
sudo <service-name> -V # (works for Apache, Nginx, etc.)
# Re-validate config syntax
sudo nginx -t
sudo apachectl configtest"Permission Denied" When Running Service Commands
Cause: Insufficient privileges.
Solution: Always use sudo or switch to the root user:
sudo systemctl restart <service-name>
# or
su -c "systemctl restart <service-name>"systemd Reports "Unit Not Found"
Cause: The service name is incorrect or the service isn't installed.
Solution:
# Search for the correct service name
sudo systemctl list-units --type=service | grep <partial-name>
# Or list all available unit files
sudo systemctl list-unit-files | grep <partial-name>Managing Services on AlexHost Infrastructure
If you're running services on AlexHost infrastructure, the service management commands covered in this guide apply directly to your environment. AlexHost's VPS Hosting plans run on modern Linux distributions with full systemd support, giving you complete control over your service stack via SSH.
For administrators who prefer a graphical interface for service management, AlexHost offers VPS with cPanel and a range of VPS Control Panels that provide GUI-based service management alongside full command-line access.
If your workload requires maximum performance and dedicated resources — for example, running high-traffic web servers, database clusters, or mail servers — consider AlexHost's Dedicated Servers, which give you full root access and complete control over your service configuration.
For teams running web applications that also need reliable email infrastructure, AlexHost's Email Hosting provides a managed solution that eliminates the complexity of configuring and maintaining mail server daemons like Postfix and Dovecot yourself.
And if you're hosting websites that handle sensitive user data, pairing your hosting with an SSL Certificate ensures encrypted connections — and remember that after installing or renewing an SSL certificate, you'll need to restart your web server daemon (Apache or Nginx) for the changes to take effect.
Conclusion
Restarting Linux services from the command line is a foundational skill that every system administrator — from beginner to expert — must have in their toolkit. The specific commands vary depending on your init system:
- systemd (modern Linux):
sudo systemctl restart <service-name> - SysVinit (legacy Linux):
sudo service <service-name> restart - Upstart (old Ubuntu):
sudo initctl restart <service-name>
But beyond knowing the commands, truly effective service management means understanding when to use reload versus restart, how to validate configuration before applying changes, how to read logs when things go wrong, and how to ensure services survive system reboots.
Master these techniques and you'll be equipped to keep your Linux servers running smoothly, minimize downtime, and resolve service issues quickly and confidently — whether you're managing a single VPS or a fleet of dedicated servers.
on All Hosting Services
